命令行方式: django-admin startproject 项目名称
pycharm方式: file ?? new project ?? django ?? 项目路径,选解释器
命令行方式:
pycharm方式:django图标下 ?? 绿色三角开始运行
html页面放在templates文件夹下
templates:settings里的TEMPLATES里的DIRS(pycharm方式的项目自动创建,终端方式的项目手动写路径)
from django.shortcuts import HttpResponse, render def index(request): return HttpResponse(‘欢迎进入红浪漫!‘) # 返回字符串 def home(request): return render(request, ‘home.html‘) # 返回html页面 urlpatterns = [ url(r‘^admin/‘, admin.site.urls), url(r‘^index/‘, index), # 路径和函数的对应关系 url(r‘^home/‘, home), ]
原文:https://www.cnblogs.com/biulo/p/11391346.html