Configuring Django and MariaDB on CentOS 7

Submitted by aknnn on Mon, 10/01/2018 - 01:07

This tutorial will demonstrate how to install Django and MariaDB on CentOS 7

Preferably inside virtual environment execute:
pip3 install django

MariaDB is needed (If you want, you can use mysql instead)
for this you need to enable MariaDB repos.

Inside /etc/yum.repos.d/ create file MariaDB.repo with contents:

[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.3/centos7-amd64
gpgkey = http://yum.madiadb.org/RPM-GPG-KEY-MariaDB
gpgcheck = 1

Install required MariaDB packages:
yum install MariaDB-server MariaDB-client

django-admin startproject project_name
This will create a folder with the project_name to the current working directory.

install pymysql (Python MySQL connector)
pip3 install pymysql

Start MariaDB, login as root, create user, add database and add permissions to user (this user will be used to connect django to database):
systemctl enable mariadb <-- makes mariadb start at boot
systemctl start mariadb  <-- root user will be created, write your credentials down for later usage.
mysql -u root -p  <-- password will be prompted.

Now you should be logged in to mariadb shell as root user. Execute following commands:
CREATE DATABASE example_database;
CREATE USER 'example_username'@'localhost;
GRANT ALL PRIVILEGES ON example_database.* TO 'example_username'@'localhost' IDENTIFIED BY 'example_password';
FLUSH PRIVILEGES;

Now you can quit mysql.

Edit project_name/project_name/__init__.py to include these lines:
import pymysql
pymysql.install_as_MySQLdb()

Go to settings.py file in the same folder. Find DATABASES dictionary and edit it as follows:

DATABASES = {
    'default' : {
        'ENGINE'        : 'django.db.backends.mysql',
        'NAME'            : 'project_name',
        'USER'            : 'example_username',
        'PASSWORD' : 'example_password',
        'HOST'            : 'localhost',
        'PORT'            : '',
    }
}

If gods are in our side, you should be able to run:
python3 manage.py runserver
if that passes, you can try to visit your server port 8000 with a web browser
SERVER_IP:8000

if that doesn't go trough, theres probably something wrong with your firewall settings. Fix them and try again.
THX.

Comments

Submitted by Barbra (not verified) on Fri, 02/08/2019 - 05:39

Permalink

Hey! I know this is kinda off topic nevertheless I'd figured I'd ask.
Would you be interested in trading links or maybe guest authoring a
blog article or vice-versa? My site addresses a lot of the same
topics as yours and I think we could greatly benefit from each other.
If you are interested feel free to send me an email. I look forward to hearing from you!
Fantastic blog by the way!

my web site - Judi Jackpot Online

Submitted by Chet (not verified) on Wed, 02/13/2019 - 11:43

Permalink

Unquestionably believe that which you said. Your favorite justification seemed to
be on the web the simplest thing to be aware of. I say to you,
I definitely get annoyed while people think about worries that they plainly do not know about.
You managed to hit the nail upon the top and also defined out the whole thing without having
side-effects , people can take a signal. Will likely be back
to get more. Thanks

Feel free to visit my webpage ... Agen Sbobet (Phoebe)

Submitted by Stefan (not verified) on Wed, 02/13/2019 - 17:21

Permalink

My coder is trying to convince me to move to .net from PHP.
I have always disliked the idea because of the expenses. But he's tryiong none the less.

I've been using Movable-type on a number of websites for about a
year and am nervous about switching to another platform.
I have heard fantastic things about blogengine.net.

Is there a way I can import all my wordpress content into it?
Any kind of help would be greatly appreciated!

my web blog ... FADOS9F1 CIRCUIT

Submitted by Joseph (not verified) on Thu, 02/14/2019 - 19:58

Permalink

Superb blog you have here but I was curious about if you knew of
any user discussion forums that cover the same topics talked about here?
I'd really love to be a part of group where I can get
comments from other experienced people that share the
same interest. If you have any suggestions, please let me know.
Bless you!

Also visit my web page :: Download Velvet Buzzsaw full movie

Submitted by Virginia (not verified) on Fri, 02/15/2019 - 23:42

Permalink

I'm really loving the theme/design of your website.
Do you ever run into any browser compatibility problems?
A couple of my blog audience have complained about
my blog not working correctly in Explorer but looks great in Firefox.

Do you have any solutions to help fix this issue?

Here is my web-site :: Agen Sbobet

Submitted by Pansy (not verified) on Sat, 02/16/2019 - 01:01

Permalink

It is perfect time to make a few plans for the future
and it is time to be happy. I've learn this post
and if I may just I want to recommend you some fascinating
things or tips. Perhaps you can write subsequent articles relating to this article.
I want to read even more issues approximately it!

Feel free to surf to my site: Agen Sbobet (Letha)

Submitted by Lilliana (not verified) on Sat, 02/16/2019 - 04:12

Permalink

Do you have a spam issue on this website; I also am a blogger,
and I was wanting to know your situation; many of us have created some
nice procedures and we are looking to swap techniques
with others, please shoot me an e-mail if interested.

Also visit my web site Taruhan Online (Lawanna)

Submitted by Salvatore (not verified) on Sat, 02/16/2019 - 23:53

Permalink

Thanks a lot for sharing this with all of us you actually know what you're speaking about!

Bookmarked. Please additionally consult with my web site =).
We may have a hyperlink change contract among us

Take a look at my page - Agen Bola, Karolin,

Submitted by Aja (not verified) on Sun, 02/17/2019 - 02:42

Permalink

Hey there just wanted to give you a quick heads up.
The text in your article seem to be running off the screen in Internet explorer.
I'm not sure if this is a format issue or something to do with internet browser compatibility but I thought I'd
post to let you know. The design and style look great though!

Hope you get the problem fixed soon. Thanks

Also visit my weblog :: Agen Bola (www.zcfcia.cn)

Submitted by Kyle (not verified) on Sun, 02/17/2019 - 07:28

Permalink

Please let me know if you're looking for a writer for your weblog.
You have some really great articles and I feel I would
be a good asset. If you ever want to take some of the load off, I'd absolutely love to write some content for your
blog in exchange for a link back to mine. Please blast me an email if interested.

Regards!

Here is my blog Agen Sbobet [Dean]

Submitted by Arlette (not verified) on Sun, 02/17/2019 - 09:11

Permalink

I love your blog.. very nice colors & theme. Did you make this
website yourself or did you hire someone to do it for you?
Plz reply as I'm looking to construct my own blog and would like
to find out where u got this from. thanks a lot

My homepage Togel Hongkong

Submitted by Dieter (not verified) on Sun, 02/17/2019 - 12:35

Permalink

Pretty section of content. I just stumbled
upon your web site and in accession capital to assert that I get actually
enjoyed account your blog posts. Anyway I will be subscribing to your feeds and even I achievement you access consistently fast.

Feel free to visit my web site - Ceme Online (Jim)

Submitted by Jenna (not verified) on Sun, 02/17/2019 - 23:42

Permalink

Hi there would you mind sharing which blog platform you're using?
I'm looking to start my own blog in the near
future but I'm having a difficult time deciding between BlogEngine/Wordpress/B2evolution and Drupal.
The reason I ask is because your layout seems different then most blogs and I'm
looking for something unique.
P.S Sorry for being off-topic but I had to ask!

Feel free to visit my web-site :: Togel Hongkong

Submitted by Lyle (not verified) on Mon, 02/18/2019 - 00:14

Permalink

The other day, while I was at work, my cousin stole my iPad and tested to see if it can survive a thirty foot
drop, just so she can be a youtube sensation. My iPad is now destroyed and she has
83 views. I know this is completely off topic but I had
to share it with someone!

Stop by my web page: Taruhan Online - Hye,

Submitted by Oma (not verified) on Mon, 02/18/2019 - 02:35

Permalink

Hey there, I think your website might be having browser compatibility issues.
When I look at your blog in Chrome, it looks fine
but when opening in Internet Explorer, it has some overlapping.

I just wanted to give you a quick heads up! Other then that,
great blog!

Feel free to visit my web blog Agen Bola, Mikki,

Add new comment