TA的每日心情 | 奋斗 2021-8-6 16:14 |
---|
签到天数: 1 天 连续签到: 1 天 [LV.1]测试小兵
|
安装各种包
俺用的是ubuntu,装包什么的最方便了.
Pip - python的包获取/安装工具,相当好用。django各个版本它都有:
sudo apt-get install python-pip
Django - 装原来用过的版本。不然的话会有很多兼容的问题(坑)。我用的是1.4.5的版本:
pip install django==1.4.5
Apache - 一般都是2.2.1吧:
sudo apt-get install apache2
MySQL - 装个server就够了:
sudo apt-get install mysql-server
MySQLdb - MySQL跟Django的data layer:
sudo apt-get install python-mysqldb
Mod_wsgi - 支持Apache模块和python应用的通信组件:
sudo apt-get install libapache2-mod-wsgi
建立app
如果你已经有项目了,直接mv项目到/var/www/下面就行了。如果是新项目,同样到www的目录下新建一
个项目:
django-admin.py startproject your-app
配置apache
cd去/etc/apache2/site-available/下,把80端口的virtualshost换了。
- <VirtualHost *:80>
- ServerAdmin your-app
- ServerName your-app.com
- DocumentRoot /var/www/your-app
- <Directory />
- Options FollowSymLinks
- AllowOverride None
- </Directory>
- <Directory /var/www/>
- Options Indexes FollowSymLinks MultiViews
- AllowOverride None
- Order allow,deny
- allow from all
- </Directory>
- ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
- <Directory "/usr/lib/cgi-bin">
- AllowOverride None
- Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
- Order allow,deny
- Allow from all
- </Directory>
- ErrorLog ${APACHE_LOG_DIR}/error.log
- # Possible values include: debug, info, notice, warn, error, crit,
- # alert, emerg.
- LogLevel warn
- CustomLog ${APACHE_LOG_DIR}/access.log combined
- Alias /doc/ "/usr/share/doc/"
- <Directory "/usr/share/doc/">
- Options Indexes MultiViews FollowSymLinks
- AllowOverride None
- Order deny,allow
- Deny from all
- Allow from 127.0.0.0/255.0.0.0 ::1/128
- </Directory>
- </VirtualHost>
复制代码
配置wsgi
在/var/www/下新建一个文件夹叫apache,然后在文件夹里面新建一个叫django.wsgi的文件,加入以下:
import os
import sys
import django.core.handlers.wsgi
sys.stdout=sys.stderr
sys.path.append(r'/var/www/your-app')
os.environ['DJANGO_SETTINGS_MODULE']='settings'
application=django.core.handlers.wsgi.WSGIHandler()
如果你有多个app分支,建议把setting分开成多个配置文件。然后再切到/etc/apache2/下面,在httpd.conf
里面加上:
WSGIScriptAlias / /var/www/apache/django.wsgi
WSGIScriptAlias / /var/www/apache/django.wsgi
###配置MySQL
mysql -u root -p yourpwd进入MySQL,建一个新的databasecreate database new_database。在setting里面
加入MySQL信息:
- DATABASES = {
- 'default': {
- 'ENGINE': 'django.db.backends.mysql',
- 'NAME': 'new_database',
- 'USER': 'root',
- 'PASSWORD': 'your password',
- 'HOST': 'localhost',
- 'PORT': '3306',
- }
- }
复制代码
配置settings
一些路径的配置:
INSTALLED_APPS = ('your-app') #加入你的app
DEBUG = True #开debug,如果是prod请设置成False
TEMPLATE_DEBUG = DEBUG
SITE_URL = '/var/www/your-app'
MEDIA_ROOT = SITE_URL + '/media/'
TEMPLATE_DIRS = (SITE_URL + '/template',)
STATIC_PATH = SITE_URL + "/static/"
|
|