【django轻量级框架】云端系统之Django框架

1 Web框架

在这里插入图片描述

2 工程目录结构

在这里插入图片描述
只要关注settings.py和urls.py即可!

3 调试运行Web框架

这时,不对工程进行任何路由修改。

C:\Users\88304>cd mysite

C:\Users\88304\mysite>python manage.py runserver
Performing system checks...

System check identified no issues (0 silenced).

You have 14 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
March 05, 2020 - 20:39:10
Django version 2.0, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
[05/Mar/2020 20:39:24] "GET / HTTP/1.1" 200 16559
[05/Mar/2020 20:39:24] "GET /static/admin/css/fonts.css HTTP/1.1" 200 423
Not Found: /favicon.ico
[05/Mar/2020 20:39:24] "GET /static/admin/fonts/Roboto-Bold-webfont.woff HTTP/1.1" 200 82564
[05/Mar/2020 20:39:24] "GET /favicon.ico HTTP/1.1" 404 1972
[05/Mar/2020 20:39:24] "GET /static/admin/fonts/Roboto-Regular-webfont.woff HTTP/1.1" 200 80304
[05/Mar/2020 20:39:24] "GET /static/admin/fonts/Roboto-Light-webfont.woff HTTP/1.1" 200 81348

3.1 Django admin

在这里插入图片描述
在这里插入图片描述

3.2 manage.py

同为管理工具。

4 创建一个具体应用

C:\Users\88304\mysite>manage.py startapp helloapp

在这里插入图片描述

4.1 修改应用的view.py

在这里插入图片描述

在这里插入图片描述

from django.shortcuts import render

# Create your views here.
from django.http import HttpResponse
def hello(request):
    return HttpResponse("hello")

4.2 修改URL路由

在这里插入图片描述

5 效果

在这里插入图片描述

6 MTV开发模式

在这里插入图片描述
在这里插入图片描述

6.1 在hello2app,配置本地路由文件

在这里插入图片描述

6.2 增加对本地路由的引用

"""mysite URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/2.0/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path,include
from helloapp import views
urlpatterns = [
    path('index2/',include('helloapp.urls')),
    path('index/',views.hello),
    path('admin/', admin.site.urls),
]

6.3 设置模板路径

在这里插入图片描述

发布了829 篇原创文章 · 获赞 215 · 访问量 7万+

猜你喜欢

转载自blog.csdn.net/weixin_43838785/article/details/104683290