Django deployment and contact app demo

Django deployment

1, deploy on the server

  
  
  
  
  1. #:django-admin startproject mysite 
  2. #:cd mysite/ 

 

2, create a "django.wsgi" file, add and edit the code like:

  
  
  
  
  1. #!/usr/bin/env python 
  2. import os, sys 
  3.  
  4. # make sure app's modules can be found 
  5. sys.path.append('/home/userid'
  6. sys.path.append('/home/userid/djangoproject'
  7. os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' 
  8.  
  9. # Switch to the directory of your project. (Optional.) 
  10. # os.chdir("/home/userid/djangoproject") 
  11.  
  12. import django.core.handlers.wsgi 
  13. application = django.core.handlers.wsgi.WSGIHandler() 

 

3, To alias this app to the URL, and start the setup process, edit /etc/apache2/sites-enabled/000-default and at the bottom of the <Virtualhost> section (right before the “</Virtualhost>”), add this:

  
  
  
  
  1. WSGIScriptAlias /mysite /home/userid/djangoproject/django.wsgi 
  2. WSGIDaemonProcess mysite user=userid 
  3. <Directory /home/userid/djangoproject/> 
  4.   WSGIProcessGroup mysite 
  5. </Directory> 

 

4, Then go back to djangoproject directory and input

  
  
  
  
  1. #:sudo /etc/init.d/apache2 restart 
  2. #:python manage.py runserver 

try "https://www.example.com/mysite/" and you can see "Welcome to Django site".

 

5,Database setup (I am using mysql as example)

edit "/mysite/settings.py"

 

本文出自 “PP技术流” 博客,转载请与作者联系!

你可能感兴趣的:(django)