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 3, 2020 in Python by kartik
• 37,520 points
1,798 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 3, 2020 by Niroj
• 82,840 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
• 58,020 points
1,168 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,150 points
969 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, 2020 in Python by sahil
• 500 points
2,032 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,020 points
1,563 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, 2020 in Python by Niroj
• 82,840 points
2,508 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, 2020 in Python by Niroj
• 82,840 points
1,586 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, 2020 in Python by Niroj
• 82,840 points
834 views
0 votes
1 answer

How to Creat a JSON response using Django and Python?

Hello @kartik, I usually use a dictionary, not ...READ MORE

answered Aug 6, 2020 in Python by Niroj
• 82,840 points
3,157 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP