如何停止得到这个“未找到” URL路由在Django错误

问题描述 投票:0回答:1

虽然两个链接是完全一样的,我不断收到一个“/下一页在/帐号/登录没有发现?”错误,每当我点击我的链接。是什么在我的代码中的错误? “探索”的作品,但“发生”不!请帮忙!

views.朋友

def explore(request):
    return render(request, 'explore.html')

def happening(request):
    return render(request, 'happening.html')

HTML模板

  <div id="happening_log">
     <a style= "padding-left:5px" href="{% url 'happening' 
          %}">Happening</a>
  </div>

URLs.朋友

urlpatterns = [
     path('', views.explore, name='explore'),
     path('<user__name>/', views.home, name='home'),
     path('happening/', views.happening, name='happening'),
]

找不到网页(404)请求方法:GET请求URL:http://127.0.0.1:8000/accounts/login/?next=/happening/使用mysite.urls定义的URL配置,Django的尝试这些URL模式,顺序如下:

admin/
[name='explore']
<user__name>/ [name='home']
/happening/ [name='happening']
users/
^static\/(?P<path>.*)$
^media\/(?P<path>.*)$
The current path, accounts/login/, didn't match any of these.
python django
1个回答
0
投票

你有没有在您的项目现场登记/ login.html的文件吗?网址,http://127.0.0.1:8000/accounts/login/?next=/happening/正在访问登录的模板,所以你必须做出一个默认注册/ login.html的或其他登录像下面一样;

def login(request):

    if request.method == 'POST':
        form = LoginForm(request.POST)

        if form.is_valid():
            username=form.cleaned_data.get('username')
            password=form.cleaned_data.get('password')
            user = authenticate(username=username, password=password)

            if user and user.profile.status == 'WORKING':
                auth.login(request, user)

                if user.profile.passwd:
                    return redirect('myprofile')
                else:
                    return redirect('password')
    else:
        form = LoginForm()

    return render(request, 'accounts/login.html', {'form': form})
© www.soinside.com 2019 - 2024. All rights reserved.