Bootstrap

Django网址与视图

Project实例
在这里插入图片描述

#settings.py
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'learn',
]
#views.py
from django.http import HttpResponse
def index(requst):
    return HttpResponse("Hello world")
#urls.py
from learn import views as learn_views
urlpatterns = [
    path("", learn_views.index),
    path('admin/', admin.site.urls),
]

常见文件说明

  • urls.py:网址入口
  • views.py:渲染templates中网页,并显示
  • models.py:数据库操作相关
  • forms.py:表单,网页提交相关
  • templates:views.py中渲染的html模板
  • admin.py:后台
  • settings.py:Django配置
;