美文网首页
创建模板template

创建模板template

作者: Mr_phq | 来源:发表于2019-04-07 20:27 被阅读0次

1、在应用blog下新建一个文件夹:new->Directory ,命名为templates,在templates下新建一个与应用同名的文件夹blog,在刚刚创建好的blog文件夹下新建一个HTML文档,命名为index。

2、在myblog下的urls.py中导入include模块(函数),添加如下代码:

3、在应用blog下新建一个urls.py文件,添加如下代码:

4、更改views.py中index视图的代码:

启动服务:python manage.py runserver,在浏览器地址栏中输入:127.0.0.1:8000/blog/index,效果如下:

注意事项:在第三步的urls.py中path函数的第一个参数,即字符串后一定要有斜杠,不然会报找不到路径。

相关文章

网友评论

      本文标题:创建模板template

      本文链接:https://www.haomeiwen.com/subject/omceiqtx.html