ubuntu14-04+python3-4+apache2-4+django1-10
操作系统安装略
python3.4安装略
mysql安装略
--------------------------------------------
apache2安装Apache/2.4.7
apt-get install apache2
apache会在var下创建www目录,要访问的web文件就在此目录下
检查是否安装成功
http://localhost
it works
常用命令
#重启 apache
sudo /etc/init.d/apache2 restart
#开启 apache
sudo /etc/init.d/apache2 start
#关闭 apache
sudo /etc/init.d/apache2 stop
安装libapache2-mod-wsgi-py3
apt-get insatll libapache2-mod-wsgi-py3
apaceh集成django配置
修改apache2.conf
添加如下内容:
ServerName localhost
gedit /etc/apache2/sites-enabled/000-default.conf
添加如下内容
<VirtualHost *:80>
ServerName 192.168.1.105
DocumentRoot /home/retacn/jkx
<Directory '/home/retacn/jkx'>
Require all granted
</Directory>
WSGIScriptAlias / /home/retacn/jkx/jkx/apache/wsgi.py
</VirtualHost>
#重启 apache
sudo /etc/init.d/apache2 restart
查看apache错误日志
gedit /var/log/apache2/error.log
查看结果
http://192.168.1.105/jkxapp
--------------------------------------------------
Django安装
pip3 install Django
查看安装的版本号
>>> import django
>>> print(django.get_version())
1.10.2
创建应用
cd /home/retacn
django-admin.py startproject jkx
运行此项目
cd /home/jkx/retacn
django-admin.py startapp jkxapp
cd /home/retacn/jkx/jkx
修改setting.py添加如下内容:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'jkxapp',
]
修改urls.py.添加如下内容:
from jkxapp import views
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'jkxapp',views.home_view),
]
cd /home/retacn/jkx/jkxapp
修改viesw.py,添加如下内容:
from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.
def home_view(request):
return HttpResponse('Hello word')
运行服务
python3 manage.py urnserver
可以在运行时改变地址和端口号
python3 manage.py runserver 0.0.0.0:8080
查看运行结果:
http://127.0.0.1:8000/helloapp
修改目录结果
原目录结果为:
jkx/
manage.py
jkx/
__init__.py
settings.py
urls.py
jkxapp/
...
models.py
views.py
修改后目录为:
jkx/
manage.py
jkx/
__init__.py
settings.py
urls.py
apache/
__init__.py
override.py
wsgi.py
jkxapp/
...
models.py
views.py
其中apache为新源加目录
mkdir apache
cd apache
gedit __init__.py
__init__.py为空文件,告诉python该目录当成包来结待
gedit override.py,添加如下内容:
#override.py
from jkx.settings import *
DEBUG = True
#ALLOWED_HOSTS=['www.***.com','***.com']
gedit wsgl.py,添加如下内容:
#wsgi.py
import os, sys
from django.core.wsgi import get_wsgi_application
# Calculate the path based on the location of the WSGI script.
apache_configuration= os.path.dirname(__file__)
project = os.path.dirname(apache_configuration)
workspace = os.path.dirname(project)
sys.path.append(workspace)
sys.path.append(project)
# Add the path to 3rd party django application and to django itself.
sys.path.append('/home/retacn')
os.environ['DJANGO_SETTINGS_MODULE'] = 'jkx.apache.override'
import django.core.handlers.wsgi
#application = django.core.handlers.wsgi.WSGIHandler()
application=get_wsgi_application()
为apache服务器分配该目录的所有权
chown www-data:www-data apache/
运行服务
python3 manage.py urnserver
报以下错误:
You have 15 unapplied migration(s). Your project may not work properly until you apply
the migrations for app(s): admin, auth, contenttypes, sessions, sites.
Run 'python manage.py migrate' to apply them.
解决办法:
#可以修改model,在不影响现有数据的情况下,重建表结构
python3 manage.py migrate
错误:
Error: That port is already in use.
ps aux | grep -i manage
kill -9 id
python3.4安装略
mysql安装略
--------------------------------------------
apache2安装Apache/2.4.7
apt-get install apache2
apache会在var下创建www目录,要访问的web文件就在此目录下
检查是否安装成功
http://localhost
it works
常用命令
#重启 apache
sudo /etc/init.d/apache2 restart
#开启 apache
sudo /etc/init.d/apache2 start
#关闭 apache
sudo /etc/init.d/apache2 stop
安装libapache2-mod-wsgi-py3
apt-get insatll libapache2-mod-wsgi-py3
apaceh集成django配置
修改apache2.conf
添加如下内容:
ServerName localhost
gedit /etc/apache2/sites-enabled/000-default.conf
添加如下内容
<VirtualHost *:80>
ServerName 192.168.1.105
DocumentRoot /home/retacn/jkx
<Directory '/home/retacn/jkx'>
Require all granted
</Directory>
WSGIScriptAlias / /home/retacn/jkx/jkx/apache/wsgi.py
</VirtualHost>
#重启 apache
sudo /etc/init.d/apache2 restart
查看apache错误日志
gedit /var/log/apache2/error.log
查看结果
http://192.168.1.105/jkxapp
--------------------------------------------------
Django安装
pip3 install Django
查看安装的版本号
>>> import django
>>> print(django.get_version())
1.10.2
创建应用
cd /home/retacn
django-admin.py startproject jkx
运行此项目
cd /home/jkx/retacn
django-admin.py startapp jkxapp
cd /home/retacn/jkx/jkx
修改setting.py添加如下内容:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'jkxapp',
]
修改urls.py.添加如下内容:
from jkxapp import views
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'jkxapp',views.home_view),
]
cd /home/retacn/jkx/jkxapp
修改viesw.py,添加如下内容:
from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.
def home_view(request):
return HttpResponse('Hello word')
运行服务
python3 manage.py urnserver
可以在运行时改变地址和端口号
python3 manage.py runserver 0.0.0.0:8080
查看运行结果:
http://127.0.0.1:8000/helloapp
修改目录结果
原目录结果为:
jkx/
manage.py
jkx/
__init__.py
settings.py
urls.py
jkxapp/
...
models.py
views.py
修改后目录为:
jkx/
manage.py
jkx/
__init__.py
settings.py
urls.py
apache/
__init__.py
override.py
wsgi.py
jkxapp/
...
models.py
views.py
其中apache为新源加目录
mkdir apache
cd apache
gedit __init__.py
__init__.py为空文件,告诉python该目录当成包来结待
gedit override.py,添加如下内容:
#override.py
from jkx.settings import *
DEBUG = True
#ALLOWED_HOSTS=['www.***.com','***.com']
gedit wsgl.py,添加如下内容:
#wsgi.py
import os, sys
from django.core.wsgi import get_wsgi_application
# Calculate the path based on the location of the WSGI script.
apache_configuration= os.path.dirname(__file__)
project = os.path.dirname(apache_configuration)
workspace = os.path.dirname(project)
sys.path.append(workspace)
sys.path.append(project)
# Add the path to 3rd party django application and to django itself.
sys.path.append('/home/retacn')
os.environ['DJANGO_SETTINGS_MODULE'] = 'jkx.apache.override'
import django.core.handlers.wsgi
#application = django.core.handlers.wsgi.WSGIHandler()
application=get_wsgi_application()
为apache服务器分配该目录的所有权
chown www-data:www-data apache/
运行服务
python3 manage.py urnserver
报以下错误:
You have 15 unapplied migration(s). Your project may not work properly until you apply
the migrations for app(s): admin, auth, contenttypes, sessions, sites.
Run 'python manage.py migrate' to apply them.
解决办法:
#可以修改model,在不影响现有数据的情况下,重建表结构
python3 manage.py migrate
错误:
Error: That port is already in use.
ps aux | grep -i manage
kill -9 id