如何解决Django没有重定向到正确的页面
我得到的是: (从登录页面重定向)
#Ask how many hours the employee worked this week and assign that value to a varaible
prompt = "How many hours did you work this week?"
total_hours = float(input(prompt))
#Ask how much revenue the employees total sales for the week brought in
prompt = "How much revenue did your weekly sales bring in?"
weekly_sales_revenue = float(input(prompt))
#assign hourly wage and commision rate to their own variables
hourly_wage = 20
commission = .10
#perform calculation for total pay as number of hours worked times hourly wage plus commision revenue times commission rate
print(total_hours*hourly_wage + weekly_sales_revenue * commission)
我想重定向到注册/页面,但是django转到登录/注册。
我的主要项目网址:
Using the URLconf defined in webapp.urls,Django tried these URL patterns,in this order:
admin/
[name='blog-home']
about/ [name='blog-about']
register/ [name='register']
login/ [name='login']
logout/ [name='logout']
The current path,login/{ url 'register' },didn't match any of these.
(Pycharm在此文件中找不到用户模块,但是django不会报告任何错误,并且完全可以解决问题)
我的主要项目已安装的应用程序:
from django.contrib import admin
from django.contrib.auth import views as auth_views
from django.urls import path,include
from users import views as user_views
urlpatterns = [
path('admin/',admin.site.urls),path('',include('blog.urls')),path('register/',user_views.register,name='register'),path('login/',auth_views.LoginView.as_view(template_name='users/login.html'),name='login'),path('logout/',auth_views.LogoutView.as_view(template_name='users/logout.html'),name='logout'),]
我添加到主项目设置中的内容。py:
INSTALLED_APPS = [
'blog.apps.BlogConfig','users.apps.UsersConfig','crispy_forms','django.contrib.admin','django.contrib.auth','django.contrib.contenttypes','django.contrib.sessions','django.contrib.messages','django.contrib.staticfiles',]
用户views.py:
CRISPY_TEMPLATE_PACK = 'bootstrap4'
LOGIN_REDIRECT_URL = 'blog-home'
LOGIN_URL = 'login'
谢谢!
解决方法
您的login.html
模板可能有问题。您可能在其中有这样的链接:
<a href="{ url 'register' }">Register</a>`
除非要更改Django的默认模板运算符,否则应使用{%
作为url模板标记:
<a href="{% url 'register' %}">Register</a>`
阅读Django有关模板的页面可能是一个好主意:https://docs.djangoproject.com/en/3.1/topics/templates/
以下是url
标记特定的文档:
https://docs.djangoproject.com/en/3.1/ref/templates/builtins/#url
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。