【1.3】Django HelloWorld

1.Django视图(What、Why&How)

  There is no time frame: hello.html

  Impossible to express all of the content pages through HTML

  Django view generated content

 

2.Django路由(What、Why&How)

  Django runserver can see the welcome page

  Request just no way to reach the view function

  You need to configure the routing function and binding view URL

 

Configuration, application views.py

1 from django.shortcuts import render
2 from django.http import HttpResponse
3 
4 # Create your views here.
5 
6 
7 def hello_world(request):
8     return HttpResponse('Hello World')

 

Establish urls.py

 1 #!/usr/bin/env python
 2 # -*- coding:utf-8 -*-
 3 
 4 from django.urls import path, include
 5 
 6 import blog.views
 7 
 8 urlpatterns = [
 9     path('hello_world', blog.views.hello_world)
10 ]

 

Project urls.py

1 from django.contrib import admin
2 from django.urls import path, include
3 
4 urlpatterns = [
5     path('admin/', admin.site.urls),
6     path('blog/', include('blog.urls')) # 转发到应用
7 ]

 

Project settings.py

 1 INSTALLED_APPS = [
 2     'django.contrib.admin',
 3     'django.contrib.auth',
 4     'django.contrib.contenttypes',
 5     'django.contrib.sessions',
 6     'django.contrib.messages',
 7     'django.contrib.staticfiles',
 8 
 9     # my_app
10     'blog.apps.BlogConfig',
11 ]

 

Guess you like

Origin www.cnblogs.com/zydeboke/p/11443636.html