我一直在阅读文档,并且已经回答了几个问题,但是似乎没有任何效果,因此这里是一个问题。我以django开头,无法摆脱以下错误:
Using the URLconf defined in alpha_trader.urls, Django tried these URL patterns, in this order:
__debug__/
[name='home']
accounts/update [name='user_change']
accounts/ login/ [name='login']
accounts/ logout/ [name='logout']
accounts/ password_change/ [name='password_change']
accounts/ password_change/done/ [name='password_change_done']
accounts/ password_reset/ [name='password_reset']
accounts/ password_reset/done/ [name='password_reset_done']
accounts/ reset/<uidb64>/<token>/ [name='password_reset_confirm']
accounts/ reset/done/ [name='password_reset_complete']
accounts/signup [name='user_signup']
The current path, accounts/update.html, didn't match any of these.
这里是我的settings.py:
# Custom Django auth settings
AUTH_USER_MODEL = 'accounts.User'
LOGIN_URL = 'login'
LOGOUT_URL = 'logout'
LOGIN_REDIRECT_URL = 'home'
LOGOUT_REDIRECT_URL = 'home'
此处urls.py:
from django.urls import include, path
from django.conf import settings
from accounts import views
urlpatterns = [
path('', include('accounts.urls')),
path('accounts/', include('django.contrib.auth.urls')),
path('accounts/signup', views.SignUpView.as_view(), name='user_signup'),
]
特此帐户/urls.py:
from django.urls import include, path
from accounts import views
urlpatterns = [
path('', views.home, name='home'),
path('accounts/update', views.UserUpdateView.as_view(), name='user_change'),
]
特此account / views.py:
def home(request):
if request.user.is_authenticated:
return redirect('accounts/home.html')
return render(request, 'accounts/home.html')
最后是account / models.py:
from django.contrib.auth.models import AbstractUser
from django.db import models
from django.utils.html import escape, mark_safe
class User(AbstractUser):
is_student = models.BooleanField(default=False)
num_of_saved_backtests=models.IntegerField(default=0)
num_of_online_indicators=models.IntegerField(default=0)
有人在我的代码中看到错误吗? 重要信息当我没有登录时,我可以在家中使用。我以用户身份登录后无法使用...
答案 0 :(得分:0)
return redirect('accounts/home.html')
在这一行中,请勿重定向到文件路径,而是可以使用函数名或 url名,具体取决于在您要重定向到的视图上。
return redirect('url_name') # or redirect('function_name')
在条件相同的情况下,重定向也不能指向相同的视图,这将归结为无限循环。