django文字中转网站

2016-12-04  本文已影响0人  wildsre

django的网站搭建

参考:官方文档
注意: 操作均在virtualenv中进行,虚拟目录为web-share/

class Fuck(models.Model):
       a=1
INSTALLED_APPS = [
'writefile.apps.WritefileConfig',
]
python manage.py makemigrations
python manage.py migrate
from django.conf.urls import url 
from . import views
urlpatterns =[
       url(r'^$', views.getmsg, name='getmsg'),
]

url()的正则匹配:不会匹配域名和表单,在上面的作用是域名后不加任何字符,就调用getmsg函数

from django.conf.urls import url, include
urlpatterns = [
url(r'^$', include('writefile.urls')),
]

django查找urls的流程:
-> mysite/mysite/urls.py ->(通过include) mysite/writefile/urls.py->(正则匹配) 调用writefile/views.py中的函数

def getmsg(request):
    template = loader.get_template("writefile/index.html")
    ....
    return HttpResponse(template.render(cont, request))

cont为与html中变量有关的字典

将adjango项目部署到nginx+uwsgi

按照ubuntu中web服务器配置nginx+uwsgi+django中步骤进行,不同的是,方便起见,将django的端口设置为默认端口,这与nginx中的默认端口冲突,因此需要将/etc/nginx/sites-available/default的80端口改成其它的
mysite_nginx.conf 文件

# the upstream component nginx needs to connect to
upstream django {
    server unix:/home/zooo/web-share/mysite/mysite.sock; # for a file socket
    #server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}

# configuration of the server
server {
    # the port your site will be served on
    listen      80;
    # the domain name it will serve for
    server_name localhost; # substitute your machine's IP address or FQDN
    charset     utf-8;

    # max upload size
    client_max_body_size 75M;   # adjust to taste

    # Django media
    location /media  {
        alias /home/zooo/web-share/mysite/media; 
        autoindex on;
    }

    location /static {
        alias /home/zooo/web-share/mysite/static;
    }

    # Finally, send all non-media requests to the Django server.
    location / {
        uwsgi_pass  django;
        include     /home/zooo/web-share/mysite/uwsgi_params;
    }
}

mysite_uwsgi.ini文件

# mysite_uwsgi.ini file
[uwsgi]

# Django-related settings
# the base directory (full path)
chdir           = /home/zooo/web-share/mysite
# Django's wsgi file
module          = mysite.wsgi
# the virtualenv (full path)
home            = /home/zooo/web-share/

# process-related settings
# master
master          = true
# maximum number of worker processes
processes       = 4
# the socket (use the full path to be safe
socket          = /home/zooo/web-share/mysite/mysite.sock
# ... with appropriate permissions - may be needed
chmod-socket    = 666
上一篇下一篇

猜你喜欢

热点阅读