当前位置 博文首页 > Weiyaner的博客:Django web开发1(环境部署+第一个web程序)
pip install django==1.11.7 -i https://pypi.douban.com/simple
在Django的哲学中,我们有两个重要的概念:
views.py:这是我们处理Web应用程序请求(request)/响应(resopnse)周期的文件。
在view文件中,可以直接编写html程序,也可以在templates文件夹中新建html文件,在view中直接调用
from __future__ import unicode_literals
from django.http import HttpResponse
from django.shortcuts import render
# Create your views here.
from superweiyan.models import Students
def index(request):
return render(request,'1.html')
def index2(request):
return HttpResponse('<h1>一级标题<h2>'
'<h2>二级标题<h2>'
'<h3>三级标题<h3>')
def weather(request):
return render(request, 'weather.html') #无论是HttpResponse还是render,都是一种响应
from django.conf.urls import url
from django.contrib import admin
from superweiyan import views
urlpatterns = {
url(r'^admin/', admin.site.urls),
url(r'index', views.index),
url(r'index2', views.index2),
url(r'weather', views.weather),
url(r'getstudents', views.getstudents),
}
点击运行后,出现以下界面:
System check identified no issues (0 silenced).
June 25, 2019 - 10:57:03
Django version 1.11.7, using settings ‘Helloworld.settings’
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
其中,打开那个网址,在后面输入urls.py文件中定义的网页名称,即出现以下的界面
那么到此为止,第一个界面的编写完成了,下一篇说明数据库的连接