Django疯狂的URL重写

时间:2018-12-11 22:33:25

标签: python django templates url

我目前遇到一个我根本不了解的问题,我搜索了整个代码,在那儿找不到任何引用,删除了所有缓存,数据库,venv等。全部。

与“登录”网址格式有关

urls.py

from Project_Accounts import views as Project_Accounts
....
    url(r'^admin/', admin.site.urls),
    # Reg and Auth
    url(r'^login/$', Project_Accounts.login, name='login'),
    url(r'^signup/$', Project_Accounts.signup, name='signup'),
....

urlpatterns += [
    path('Project_Accounts/', include('django.contrib.auth.urls')),
]

base.html

{% if user.is_anonymous %}
    <a href="{% url 'signup' %}" class="top-menu">
        <button type="button" class="btn btn-success">Sign-Up</button>
    </a>
    <a href="{% url 'login' %}" class="top-menu">
        <button type="button" class="btn btn-primary">Login</button>
    </a>
{% endif %}

views.py(Project_Accounts)

def login(request):
    if request.method == 'POST':
        form = LoginForm(request.POST, request.POST)
        if form.is_valid():
            username = request.POST['username']
            password = request.POST['password']
            user = authenticate(request, username=username, password=password)
            if user is not None:
                request.session.flush()
                if user.pubpgp:
                    if user.pubpgp_enabled:
                        request.session['userID'] = user.pk
                        return redirect(reverse('login_2fa'))
                    else:
                        hybridlogin(request, user)
                        return redirect(reverse('home'))
                else:
                    hybridlogin(request, user)
                    # Redirect to a success page.
                    return redirect(reverse('home'))
        else:
            return render(request, 'Project_Accounts/login.html', {'form': form})
    else:
        return render(request, 'Project_Accounts/login.html', {'form': LoginForm()})

如果显示了我的base.html,则注册视图可以正常工作,除登录名外,其他视图也都可以。我返回登录的URL是

127.0.0.1:8000/Project_Accounts/login

但它曾经是

127.0.0.1:8000/login

知道为什么会出现吗?!

这里真的没有参考,WSGI服务器生成的错误是:

TemplateDoesNotExist at /Project_Accounts/login/
registration/login.html
Request Method: GET
Request URL:    http://127.0.0.1:8000/Project_Accounts/login/
Django Version: 2.1.4
Exception Type: TemplateDoesNotExist
Exception Value:    
registration/login.html

registration / login.html的来源是什么??!?

对我毫无意义,在我的代码中也找不到任何引用。

我很感谢每一个提示。

亲切的问候。

0 个答案:

没有答案