How to use Python 3 and Django with Apache?

0 votes

My goal is to set up Python 3 with Apache. My biggest problem is actually acquiring mod_python.so. so how can we do that?Any help?

Jul 2 in Python by kartik
• 19,650 points
54 views

1 answer to this question.

0 votes

Hello @kartik,

1) The first thing we should do with our newly created project files is adjust the settings. Open the settings file with your text editor:

gedit myproject/settings.py

At the bottom of the file, we will add a line to configure this directory. Django uses the STATIC_ROOT setting to determine the directory where these files should go. We'll use a bit of Python to tell it to use a directory called "static" in our project's main directory:

STATIC_ROOT = os.path.join(BASE_DIR, "static/")

2) We can collect all of the static content into the directory location we configured by typing:

./manage.py collectstatic

You will have to confirm the operation. The static files will be placed in a directory called static within your project directory.

3)You need mod-wsgi adapter to configure Django in Apache install wsgi lib like below.

sudo apt-get install libapache2-mod-wsgi sudo a2enmod wsgi

4)At the bottom of file, /etc/apache2/sites-available/000-default.conf

WSGIPythonPath /var/www/html/myproject/ 
WSGIProcessGroup myproject
WSGIScriptAlias / /var/www/html/myproject/myproject/wsgi.py


  Alias /static /var/www/html/myproject/static/

<Directory /var/www/html/myproject/static>
    Require all granted
</Directory>

<Directory /var/www/html/myproject/myproject>
    <Files wsgi.py>
         Order deny,allow
        Require all granted
    </Files>
</Directory>

Alias /media/ /var/www/html/myproject/media/
<Directory /var/www/html/myproject/media>
Require all granted
</Directory> 
WSGIDaemonProcess myproject python-path=/var/www/html/myproject/

5)Restart the apache2 server:

sudo service apache2 restart

6)Now go to Localhost:

Hope it works!!

Thank You!

answered Jul 2 by Niroj
• 41,480 points

Related Questions In Python

0 votes
1 answer

How to use string.replace() in python 3.x

replace() is a method of <class 'str'> ...READ MORE

answered Aug 3, 2018 in Python by Priyaj
• 57,550 points
253 views
+1 vote
1 answer

How to use GUI that comes with Python to test your code?

Hey @alex0809, When your testing a website ...READ MORE

answered Sep 24, 2018 in Python by Vardhan
• 13,200 points
158 views
0 votes
4 answers

What is a Tuple in Python and how to use it?

Tuples  are a  Unchanging sequence of values, ...READ MORE

answered Jun 21 in Python by sahil
• 540 points
396 views
0 votes
1 answer

How to install and use myql connector in Python?

You can use pip to search if ...READ MORE

answered Jul 5, 2019 in Python by Neel
• 3,010 points
218 views
0 votes
1 answer

How to temporarily disable a foreign key constraint in MySQL?

Hello @kartik, To turn off foreign key constraint ...READ MORE

answered Jun 23 in Python by Niroj
• 41,480 points
58 views
0 votes
1 answer

How do I use Django templates without the rest of Django?

Hello @kartik, Let's say you have this important ...READ MORE

answered Jun 23 in Python by Niroj
• 41,480 points
40 views
0 votes
1 answer

How to use MySQLdb with Python and Django?

Hello @kartik, I had the same error and pip ...READ MORE

answered Jun 24 in Python by Niroj
• 41,480 points
33 views
0 votes
1 answer

How to pretty-print a numpy.array without scientific notation and with given precision?

Hii @kartik, The numpy arrays have the method round(precision) which ...READ MORE

answered Apr 14 in Python by Niroj
• 41,480 points
240 views