Deploying old Django site to new server

左心房为你撑大大i 提交于 2019-12-18 09:52:08

问题


I've been handed a dump of a Django site that I'm trying to help restore on a new server for a friend. I'm not really experienced with Django, which is why I probably need some dumbed-down answers for this. I do have a dump of the database seperately, but for now I'm just trying to restore the app itself.

In the main dir of the dump (/home/naturligvis), there is a "public_html" dir, with a "hander.wsgi" file in it, that has the following code:

import os
import sys

for path in ('/home/naturligvis/lib/python/PIL/',
         '/home/naturligvis/lib/python/',
         '/home/naturligvis/naturligvis-bzr/modules/',):
if path not in sys.path:
sys.path.insert(0, path)

os.environ['DJANGO_SETTINGS_MODULE'] = 'naturligvis.psisettings'

import django.core.handlers.wsgi

application = django.core.handlers.wsgi.WSGIHandler()

Now I'm trying to figure out what kind of setup I need to do on a server (Trying with Ubuntu 16.04 on DigitalOcean) in order to make this work...? All the settings.py etc. files are in /home/naturligvis/naturligvis-bzr/modules/naturligvis

Hoping that someone can help me or point me in the right direction.


回答1:


you can try like this

import os

from django.core.wsgi import get_wsgi_application

import sys   
sys.path.append('/home/naturligvis/naturligvis-bzr/modules/')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "your_project.settings")
application = get_wsgi_application()

if you use python2

sudo apt-get install python-pip apache2 libapache2-mod-wsgi

if you use python3

sudo apt-get install python3-pip apache2 libapache2-mod-wsgi-py3

your apache virtual host config should be like that

<VirtualHost *:80>
    ServerName dev.example.com #your server name
    ServerAlias dev.example.com #your server alias

    DocumentRoot #your document root
    WSGIProcessGroup dev.example.com
    WSGIPassAuthorization On
    WSGIDaemonProcess dev.example.com python-home=/home/robert/django/robertenv python-path=/home/robert/django/
    WSGIScriptAlias / /home/robert/django/project/wsgi.py process-group=dev.example.com

    Alias "/uploads" "/home/robert/django/uploads" #uploads directory

    <Directory #your document root>
            Require all granted

            RewriteEngine on
            RewriteCond %{REQUEST_FILENAME} -s [OR]
            RewriteCond %{REQUEST_FILENAME} -l [OR]
            RewriteCond %{REQUEST_FILENAME} -d
            RewriteRule ^.*$ - [NC,L]

            RewriteRule ^(.*) /index.html [NC,L]
    </Directory>

    <Directory /home/robert/django/uploads>
        Require all granted
    </Directory>

    <Directory /home/robert/django/project>
            <Files wsgi.py>
                    Require all granted
            </Files>
    </Directory>



来源:https://stackoverflow.com/questions/45839919/deploying-old-django-site-to-new-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!