您当前的位置: 首页 >  django
  • 2浏览

    0关注

    1477博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

【Django 2021年最新版教程3】新建一个WebApp项目并运行

软件工程小施同学 发布时间:2021-05-31 12:39:37 ,浏览量:2

 1、打开terminal窗口

 

 

 

      2、输入命令:python manage.py startapp userWeb
python manage.py startapp userWeb

 

 

 

      3、新的目录结构如下:

 

      4、修改settings.py文件,注册该工程

 

Django的开发遵循MTV模式(models, templates, views),views.py负责执行操作,models.py负责数据处理(如数据库连接),templates目录下存放网页的模板

       5、在templates下新建一个index.html文件




    
    Title


    hello world

       6、编写views.py文件,定义访问这个index.html文件的操作

 

from django.shortcuts import render

# Create your views here.
def index(request):
    return render(request, './userWeb/index.html')

 

       7、编写urls.py文件,定义访问这个index.html的url路径(使用正则表达式)

 

 

8. 运行项目:在pycharm的Terminal中输入命令运行服务器:
python manage.py runserver

在浏览器中输入url:http://127.0.0.1:8000/index/ 可以看到如下的页面

 

 

参考https://www.cnblogs.com/lone5wolf/p/13826626.html

关注
打赏
1665320866
查看更多评论
立即登录/注册

微信扫码登录

0.0432s