Django搭建简易博客教程
Django博客入门
cd /usr/local/src/
wget https://www.python.org/ftp/python/2.7.12/Python-2.7.12.tgz
tar xzvf Python-2.7.12.tgz
cd Python-2.7.12
./configure --prefix=/usr/local/python-2.7.12
make -j 4
make install
# virtualenv -p /usr/local/python-2.7.12/bin/python2.7 /usr/local/scripts/iiotdjangovirtualenv -p /usr/local/python-3.4.5/bin/python3.4 /usr/local/scripts/python3.4iiotdjango
# alias djangoenv="source /usr/local/scripts/iiotdjango/bin/activate"
alias djangoenv="source /usr/local/scripts/python3.4iiotdjango/bin/activate"
source /usr/local/scripts/iiotdjango/bin/activate
pip install django
yum install -y mysql-devel
pip install MySQL-pythonpython3 -m pip install pymysqlpip3 install mysqlclient
# apt-get install libmysqld-dev
# apt-get install libpython-dev
# 参考
http://stackoverflow.com/questions/23376103/python-3-4-0-with-mysql-database
yum install -y mysql-server
service mysqld restart
CREATE USER 'ops'@'localhost' IDENTIFIED BY '123123';GRANT ALL PRIVILEGES ON *.* TO 'ops'@'localhost';FLUSH PRIVILEGES;
CREATE USER 'ops'@'%' IDENTIFIED BY '123123';GRANT ALL PRIVILEGES ON *.* TO 'ops'@'%';FLUSH PRIVILEGES;
mysql -u root -p123123
create database iiot
python manage.py migratepython manage.py makemigrations
python manage.py createsuperuser
django-admin startproject iiotdjango
django-admin startapp ims
from __future__ import unicode_literalsfrom django.db import modelsclass ims(models.Model): lanip = models.CharField(max_length = 100) password = models.CharField(max_length = 100) type = models.CharField(max_length = 100) className = models.CharField(max_length = 100) groupName = models.CharField(max_length = 100) jifang = models.CharField(max_length = 100) jigui = models.CharField(max_length = 100) beizhu = models.CharField(max_length = 100)
def __str__(self): return self.lanipmodels的简单用法 https://docs.djangoproject.com/en/1.10/ref/models/fields/
from django.contrib import admin
from ims.models import ims
class imsAdmin(admin.ModelAdmin):
list_display=('lanip','password','type','className','groupName','jifang','jigui','suzhuji','beizhu')
search_fields = ('lanip','password','type','className','groupName','jifang','jigui','suzhuji','beizhu')
admin.site.register(ims,imsAdmin)
APP的地方加入 “ims”
DB的地方
INSTALLED_APPS = ( 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'blog',)
source /usr/local/scripts/python3.4iiotdjango/bin/activatepython manage.py runserver 0.0.0.0:8081
server {
listen 80;
charset utf-8;
server_name ims.ops.ac.cn;
location / {
proxy_pass http://127.0.0.1:8081;
}
}
pip install uwsgi
# FileName : uwsgi.ini
[uwsgi]
socket = 127.0.0.1:3031
chdir = /usr/local/scripts/python34projectpiot
wsgi-file = ./python34projectpiot/
wsgi.pyprocesses = 4
threads = 2
stats = 127.0.0.1:9191
daemonize=/var/log/nginx/uwsgi.log
uwsgi uwsgi.ini
upstream django {
server 127.0.0.1:3031;
}
server {
listen 80;
charset utf-8;
server_name ims.ops.ac.cn;
location / {
include uwsgi_params;
#proxy_set_header Host $host;
#proxy_pass http://127.0.0.1:8081;
#uwsgi_pass 127.0.0.1:3031;
uwsgi_pass django;
}
location /static {
root /usr/local/scripts/python3.4iiotdjango/lib/python3.4/site-packages/django/contrib/admin;
}
}