Django web框架开发基础-01

1. Django框架安装:

pip install django

2.新建Django项目:

  2.1 进入web工程文件夹

  2.2 新建Django工程:

  cmd 运行 django-admin startproject mysite #新建django工程

3. 新增功能:

  django-admin startapp hello #新增hello功能

3.修改APP目录下views   :

  

from django.shortcuts import render  

def hello(request):

  return render(request,'text.html')

4. 新增本地路由:

from django.urls import path
from . import views
urlpatterns = [
    path('',views.hello)
]

5.新增全局路由链接:

from django.contrib import admin
from django.urls import path,include
urlpatterns = [
    path('admin/', admin.site.urls),
    path('index/',include('hello.urls')),
]

5.修改settings:

TEMPLATES = [
    {
  'DIRS': [os.path.join(BASE_DIR,'helloapp/templates'),os.path.join(BASE_DIR,'hello2/templates')],
#加入模板文件夹链接

6.将htmli文件存入helloapp/templates路径下

7.运行工程 cmd python manage.py runserver 0.0.0.0:8080

8.创建超级管理用户

cmd python manage.py createsuperuser

猜你喜欢

转载自www.cnblogs.com/ssxsy/p/9094716.html