栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Django博客系统(展示首页)

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Django博客系统(展示首页)

1.创建首页子应用
  • 重要提示:注册成功,重定向到首页

1.创建首页应用:home

$ python manage.py startapp home

 

2.定义首页视图:IndexView

from django.views import View

class IndexView(View):
    """首页广告"""

    def get(self, request):
        """提供首页广告界面"""
        return render(request, 'index.html')

3.配置首页路由

在home子应用中创建urls.py文件,并定义子路由

from django.urls import path
from home.views import IndexView
urlpatterns = [
    path('', IndexView.as_view(),name='index'),
]

在工程的urls.py总路由中添加子应用路由引导

from django.urls import path, include

urlpatterns = [

    path('', include(('home.urls','home'),namespace='home')),
]

4.测试首页是否可以正常访问

http://127.0.0.1:8000/

5.修改注册成功后,重定向到首页

users.views

from django.shortcuts import redirect
from django.urls import reverse

# 响应注册结果
return redirect(reverse('home:index'))

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/276182.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号