Django+Nginx+Uwsgi架構部署,新建個app添加web(二)

 添加最簡單的頁面

使用這個地址的博客參考,比較詳細

https://blog.csdn.net/au55555/article/details/80023310


下面的方法沒有使用路由

一、在項目目錄下新建個app

#python manage.py startapp my_app
# ll my_app
-rw-r--r--. 1 root root  128 Dec  4 21:46 admin.py
-rw-r--r--. 1 root root  146 Dec  4 21:46 apps.py
-rw-r--r--. 1 root root    0 Dec  4 21:46 __init__.py
drwxr-xr-x. 2 root root 4096 Dec  4 21:46 migrations
-rw-r--r--. 1 root root  122 Dec  4 21:46 models.py
-rw-r--r--. 1 root root  125 Dec  4 21:46 tests.py
-rw-r--r--. 1 root root  128 Dec  4 21:46 views.py


添加web頁面

進入到新建的app下
# cd my_app
# pwd
/root/firstweb/my_app

如下新建兩個文件夾templates、static
# ll
-rw-r--r--. 1 root root  128 Dec  4 21:46 admin.py
-rw-r--r--. 1 root root  146 Dec  4 21:46 apps.py
-rw-r--r--. 1 root root    0 Dec  4 21:46 __init__.py
drwxr-xr-x. 2 root root 4096 Dec  4 21:46 migrations
-rw-r--r--. 1 root root  122 Dec  4 21:46 models.py
drwxr-xr-x. 2 root root 4096 Dec  4 21:47 static
drwxr-xr-x. 2 root root 4096 Dec  4 21:47 templates
-rw-r--r--. 1 root root  125 Dec  4 21:46 tests.py
-rw-r--r--. 1 root root  128 Dec  4 21:46 views.py

最後在templates下新建index.html
# ll templates/
total 2012
-rw-r--r--. 1 root root    1632 May 29  2018 index.html

二、修改配置文件

修改settings.py,指定到web路徑

圖片.png


修改view,指定到頁面index.html

# cat  my_app/views.py
# -*- coding: utf-8 -*-

from django.shortcuts import render,HttpResponse
def index(request):
    return render(request, "index.html", locals())


修改url,指定到配置文件的index

# cat firstweb/urls.py
"""firstweb URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/1.11/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  url(r'^$', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  url(r'^$', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.conf.urls import url, include
    2. Add a URL to urlpatterns:  url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import url
from django.contrib import admin
from firstweb import views


urlpatterns = [
    #url(r'^admin/', admin.site.urls),
    url(r'^index/',views.index),
]


三、重啓uwsgi

pkill uwsgi
uwsgi -x uwsgi_socket.xml


打開網頁測試http://xxxxx/index







原文:https://blog.csdn.net/au55555/article/details/80023310 







發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章