首页>>后端>>Python->django怎么跳转到首页(2023年最新整理)

django怎么跳转到首页(2023年最新整理)

时间:2023-12-25 本站 点击:0

导读:本篇文章首席CTO笔记来给大家介绍有关django怎么跳转到首页的相关内容,希望对大家有所帮助,一起来看看吧。

python django 做了个web ,在登录界面我想直接调用系统的login模板,可是每次登录成功之后就跳到

系统的login.html里包含一个重定向URL的next隐藏域。有这么一行:

input type="hidden" name="next" value="{{ next }}" /

登陆以后跳转到系统默认的/accounts/profile

你把value改成你想要跳转的url或者给next重新传一个url也行

求教一个关于django的 页面跳转的问题

跳转和重定向很常见的场景就是登录和注销后返回到当前页面。给你个登录和注销的例子。 比如用户正在浏览一篇文章,发现下载该文章的附件需要登录才能进行

django首页怎么做?

首页就是一个页面,

为首页建立一个template以及对应的py文件,

在py文件导入其它模块,

over

Django写的LoginView,登录成功后无法跳转回原页面,求助

You do not need to make an extra view for this, the functionality is already built in.

First each page with a login link needs to know the current path, and the easiest way is to add the request context preprosessor to settings.py (the 4 first are default), then the request object will be available in each request:

settings.py:

TEMPLATE_CONTEXT_PROCESSORS = (

"django.core.context_processors.auth",

"django.core.context_processors.debug",

"django.core.context_processors.i18n",

"django.core.context_processors.media",

"django.core.context_processors.request",

)

Then add in the template you want the Login link:

base.html:

a href="{% url django.contrib.auth.views.login %}?next={{request.path}}"Login/a

This will add a GET argument to the login page that points back to the current page.

The login template can then be as simple as this:

registration/login.html:

{% block content %}

form method="post" action=""

{{form.as_p}}

input type="submit" value="Login"

/form

{% endblock %}

django如何在用户登录后返回到原来来页面,并保持登陆状态

任何页面的头部显示登录状态的部分应该是一个block,其他页面继承此block,这个block里面写上初始化js,从后台获取登录状态

结语:以上就是首席CTO笔记为大家介绍的关于django怎么跳转到首页的全部内容了,希望对大家有所帮助,如果你还想了解更多这方面的信息,记得收藏关注本站。


本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:/Python/59917.html