gpt4 book ai didi

python - 显示未找到页面(django)

转载 作者:行者123 更新时间:2023-12-01 03:00:26 26 4
gpt4 key购买 nike

我的主页是登录页面。所以首先它会转到主页功能,如果没有登录,它将转到 login_user 功能,然后登录后它将重定向到主页。但显示找不到页面.这是我的代码。

views.py:

def login_user(request):
if request.method == "POST":
username = request.POST['username']
password = request.POST['password']
user = authenticate(username=username, password=password)
if user is not None:
if user.is_active:
login(request, user)
return redirect('/')
else:
return render(request, 'retest/login.html', {'error_message': 'Your account has been disabled'})
else:
return render(request, 'retest/login.html', {'error_message': 'Invalid login'})
return render(request, 'retest/login.html')

@login_required
def home(request):
user = request.user
if user.groups.filter(name='hod').exists():
return render(request, 'retest/hod.html', {})
elif user.groups.filter(name='principal').exists():
return render(request, 'retest/principal.html', {})
elif user.groups.filter(name='Rep').exists():
return render(request, 'retest/home.html', {})
elif user.groups.filter(name='Ajithzen').exists():
return render(request, 'event/ajithzen.html', {})
elif user.groups.filter(name='graphics').exists():
return render(request, 'event/ashok.html', {})
elif user.groups.filter(name='Event_incharge').exists():
return render(request, 'event/chair.html', {})
elif user.groups.filter(name='IEEE').exists():
return render(request, 'event/ieee.html', {})
else:
return redirect('/login')

urls.py

url(r'login^$', views.login_user, name='login_user'),
url(r'^$', views.home, name='home'),

Page not found(404)

Request Method: GET

Request URL: http://127.0.0.1:8000/accounts/login/?next=/

最佳答案

执行此操作而不是登录^$

^login$

关于python - 显示未找到页面(django),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43900454/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com