How to use Python 3 and Django with Apache?

前端 未结 5 1952
北恋
北恋 2021-02-04 13:27

My goal is to set up Python 3 with Apache. My biggest problem is actually acquiring mod_python.so. For the life of me I found only one site where it could be downloaded (http://

5条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-04 13:42

    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/
    
    
        Require all granted
    
    
    
        
             Order deny,allow
            Require all granted
        
    
    
    Alias /media/ /var/www/html/myproject/media/
    
    Require all granted
     
    WSGIDaemonProcess myproject python-path=/var/www/html/myproject/
    

    5)Restart the apache2 server:

    sudo service apache2 restart
    

    6)Now go to Localhost:

    Bingo! You are all set for Django with apache.

提交回复
热议问题