我是 Django 新手,我正在尝试制作一个学习日志网站。
当我尝试使用 login_required 函数限制我的主题时,我收到 404 错误。
这是我的代码:
from django.contrib.auth.decorators import login_required
@login_required(login_url='/users/login/')
def topics(request):
""" Show all topics."""
topics = Topic.objects.order_by("date_added")
context = {"topics": topics}
return render(request, "learning_logs/topics.html", context)
每当我在代码中使用装饰器时,都会出现此错误:
Using the URLconf defined in learning_log.urls, Django tried these URL
patterns, in this order:
admin/
users/ login [name='login']
users/ logout [name='logout']
users/ registration [name='register']
learning_logs/¨
The current path, users/login/, didn't match any of these.
url 工作正常,但是当我使用装饰器时它会中断。