로그인 버튼을 클릭 할 때 페이지를 찾을 수 없음 404

데이비드 홀 렌벡

좋습니다. 등록이 잘 작동합니다. 다음과 같은 오류를 어딘가에 오류가 있습니다.

Request Method: POST
Request URL:    http://localhost:8000/users/%7Burl%20'users:login'%20%25%7D
Using the URLconf defined in loginReg.urls, Django tried these URL patterns, in this order:
^users/ ^$ [name='index']
^users/ ^register$ [name='register']
^users/ ^success$ [name='success']
^users/ ^login$ [name='login']
^users/ ^logout$ [name='logout']
The current URL, users/{url 'users:login' %}, didn't match any of these.

나머지 양식은 로그인 섹션을 꺼낼 때 작동하므로 그런 식으로 기울이는 경향이 있습니다. models.py urls.py와 두 HTML의 일부를 포함하여 누군가가 누락 된 오류를 볼 수 있기를 바랍니다.

색인 HTML

<!DOCTYPE html>
<html>
<head>
    <title>Login and Registration</title>
</head>
<body>
    {% if messages %}
        {% for message in messages %}
            <p>{{ message }}</p>
        {% endfor %}
    {% endif %}
    <div class="register">
        <h1>Register</h1>
        <form class="" action="{% url 'users:register' %}" method="post">
            {% csrf_token %}
            <p>First Name: <input type="text" name="first_name" value=""></p>
            <p>Last Name: <input type="text" name="last_name" value=""></p>
            <p>Email: <input type="text" name="email" value=""></p>
            <p>Password: <input type="Password" name="password" value=""></p>
            <p>Confirm Password: <input type="password" name="confirm_password" value=""></p>
            <input type="submit" name="" value="Register">
        </form>
    </div>
    <div class="login">
        <h1>Login</h1>
        {% csrf_token %}
        <form class="" action="{url 'users:login' %}" method="post">
        <p>Email: <input type="text" name="email" value=""></p>
        <p>Password: <input type="Password" name="password" value=""></p>
        <input type="submit" name="" value="Login">
        </form>
    </div>
</body>
</html>

Models.py

from __future__ import unicode_literals
from django.db import models
import re, bcrypt
EMAIL_REGEX = re.compile(r'^[a-zA-Z0-9.+_-]+@[a-zA-Z0-9._-]+\.[a-zA-Z]+$')

class UserManager(models.Manager):
    def add_user(self, postData):
        errors = []
        if not len(postData['first_name']):
            errors.append('First name is required')
        if len(postData['last_name']) < 2:
            errors.append('Last name must be at least 2 characters long!')
        if not len(postData['email']):
            errors.append('Email is required!')
        if not EMAIL_REGEX.match(postData['email']):
            errors.append('Please enter a valid email!')
        check_email = self.filter(email = postData['email'])
        if check_email:
            errors.append('Sorry email already exist!')
        if len(postData['password']) < 8:
            errors.append('Password must be at least 8 characters!')
        if not postData['password'] == postData['confirm_password']:
            errors.append('Passwors must match!')

        modelsResponse = {}



        if errors:
            # failed validations
            modelsResponse ['isRegistered'] = False
            modelsResponse['errors'] = errors
        else:
            # passed validations, create a new user
            hashed_password = bcrypt.hashpw(postData['password'].encode(), bcrypt.gensalt())
            user = self.create(first_name = postData['first_name'] , last_name = postData['last_name'], password = hashed_password)
            modelsResponse ['isRegistered']= True
            modelsResponse['user'] = user

        return modelsResponse

        def login_user(self, postData):
            user = self.filter(email = postData['email'])
            errors = []
            modelsResponse = {}
            if not user:
                #invalid email
                errors.append('Invalid email!')

            else:
                #found a user match, check the password to see if they match
                if bcrypt.checkpw(postData['password'].encode(), user[0].password.encode()):
                    #login the user
                    modelsResponse['isLoggedIn'] = True
                    modelsResponse['user'] = user[0]
                else:
                    # invalid email password combination
                    errors.append('Invalid email/password combination!')

            if errors:
                modelsResponse['isLoggedIn'] = False
                modelsResponse['errors'] = errors

        return modelsResponse

class User(models.Model):
    first_name = models.CharField(max_length = 50)
    last_name = models.CharField(max_length = 50)
    email = models.CharField(max_length = 100)
    password = models.CharField(max_length =100)
    created_at = models.DateTimeField(auto_now_add = True)
    updated_at = models.DateTimeField(auto_now = True)

    objects = UserManager()

Urls.py

django.conf.urls에서 URL 가져 오기,. 뷰 가져 오기

urlpatterns = [
    url(r'^$', views.index, name= 'index'),
    url(r'^register$', views.register, name = 'register' ),
    url(r'^success$', views.success, name = 'success'),
    url(r'^login$', views.login, name = 'login' ),
    url(r'^logout$', views.logout, name = 'logout'),
]

views.py

from django.shortcuts import render, redirect
from . models import User
from django.contrib import messages

# Create your views here.
def index(request):
    return render(request, 'logReg/index.html')

def register(request):
    viewsResponse = User.objects.add_user(request.POST)
    if viewsResponse['isRegistered']:
        request.session['user_id'] = viewsResponse['user'].id
        request.session['user_fname'] = viewsResponse['user'].first_name
        return redirect('users:success')
    else:
        for errors in viewsResponse['errors']:
            messages.error(request, errors)
        return redirect('users:index')


def success(request):
    if 'user_id' not in request.session:
        messages.error(request, 'Must be logged in!')
        return redirect('users.index')
    return render(request, 'logReg/success.html')

def login(request):
    viewsResponse = User.objects.login_user(request.POST)
    if viewsResponse['isLoggedIn']:
        request.session['user_id'] = viewsResponse['user'].id
        request.session['user_fname'] = viewsResponse['user'].first_name
        return redirect('users:success')
    else:
        for errors in viewsResponse['errors']:
            messages.error(request, errors)
        return redirect('users:index')

def logout(request):
    return redirect('users.index')
카르 티크 르

오타가 있습니다

{url 'users:login' %}

해야한다

{% url 'users:login' %}
#^ missing %

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Google+ 로그인 버튼을 클릭 할 수 없음

분류에서Dev

봄 보안의 사용자 정의 Html 로그인 페이지가 로그인 버튼을 클릭 한 후 페이지를 찾을 수 없음

분류에서Dev

Zeit Now 라우팅 문제. 색인 페이지 이외의 페이지를 다시로드 할 때 404 찾을 수 없음

분류에서Dev

ID를 기반으로 데이터를 얻기 위해 세부 사항을 클릭 할 때 페이지를 찾을 수 없음

분류에서Dev

xpath 및 AndroidUIAutomator를 통해 로그인 버튼을 클릭 할 수 없습니다.

분류에서Dev

Facebook 인증을 추가 할 때 페이지를 찾을 수 없음 오류

분류에서Dev

버튼을 클릭 할 때 인형이 예상대로 작동하지 않음

분류에서Dev

Ajax로 페이지를로드 할 때 Google API를 찾을 수 없음

분류에서Dev

페이지를 찾을 수 없음 (404)

분류에서Dev

Codeighter에서 URL 값을 전달하려고 할 때 404 페이지를 찾을 수 없음

분류에서Dev

페이지를 새로 고칠 때 Angular에서 404 찾을 수 없음 오류를 어떻게 방지 할 수 있습니까?

분류에서Dev

셀레늄으로 버튼을 클릭 할 수 없음

분류에서Dev

Selenium으로 버튼을 클릭 할 수 없음

분류에서Dev

ID를 클릭하여 ID 버튼을 경고 할 수 없음

분류에서Dev

HTML 이메일 서명의 버튼을 클릭 할 수 없음

분류에서Dev

ElementClickInterceptedException Selenium이 Python 버튼을 클릭 할 수 없음

분류에서Dev

Python 셀레늄이 버튼을 클릭 할 수 없음

분류에서Dev

Laravel 이미지를 볼 때 404 페이지를 찾을 수 없음

분류에서Dev

div 오버레이로 인해 버튼을 클릭 할 수 없음-가능한 Z- 색인 문제

분류에서Dev

404 MVC 응용 프로그램을 배포 할 때 찾을 수 없음

분류에서Dev

Codeigniter의 경로-404 페이지를 찾을 수 없음

분류에서Dev

heroku로 마이그레이션 할 때 장인을 찾을 수 없음

분류에서Dev

AngularJS-동일한 URL을 클릭 할 때 페이지를 다시로드 할 수 없습니까?

분류에서Dev

버튼을 클릭 할 때 페이지가 새로 고침되는 원인 찾기

분류에서Dev

클릭 할 때 두 번째 버튼이나 다른 버튼을 비활성화 할 수 없습니다.

분류에서Dev

웹 드라이버를 사용하여 버튼을 클릭 할 수 없음

분류에서Dev

버튼을 클릭 할 수 없음-클릭 비활성화

분류에서Dev

Switch를 클릭하고 기본 상태로 돌아 가기 위해 클릭 할 때까지 onCheckedChanged에서 버튼을 호출 할 수 없습니다.

분류에서Dev

Codeigniter Controller 클래스 로그인 양식 : 404 페이지를 찾을 수 없습니다.

Related 관련 기사

  1. 1

    Google+ 로그인 버튼을 클릭 할 수 없음

  2. 2

    봄 보안의 사용자 정의 Html 로그인 페이지가 로그인 버튼을 클릭 한 후 페이지를 찾을 수 없음

  3. 3

    Zeit Now 라우팅 문제. 색인 페이지 이외의 페이지를 다시로드 할 때 404 찾을 수 없음

  4. 4

    ID를 기반으로 데이터를 얻기 위해 세부 사항을 클릭 할 때 페이지를 찾을 수 없음

  5. 5

    xpath 및 AndroidUIAutomator를 통해 로그인 버튼을 클릭 할 수 없습니다.

  6. 6

    Facebook 인증을 추가 할 때 페이지를 찾을 수 없음 오류

  7. 7

    버튼을 클릭 할 때 인형이 예상대로 작동하지 않음

  8. 8

    Ajax로 페이지를로드 할 때 Google API를 찾을 수 없음

  9. 9

    페이지를 찾을 수 없음 (404)

  10. 10

    Codeighter에서 URL 값을 전달하려고 할 때 404 페이지를 찾을 수 없음

  11. 11

    페이지를 새로 고칠 때 Angular에서 404 찾을 수 없음 오류를 어떻게 방지 할 수 있습니까?

  12. 12

    셀레늄으로 버튼을 클릭 할 수 없음

  13. 13

    Selenium으로 버튼을 클릭 할 수 없음

  14. 14

    ID를 클릭하여 ID 버튼을 경고 할 수 없음

  15. 15

    HTML 이메일 서명의 버튼을 클릭 할 수 없음

  16. 16

    ElementClickInterceptedException Selenium이 Python 버튼을 클릭 할 수 없음

  17. 17

    Python 셀레늄이 버튼을 클릭 할 수 없음

  18. 18

    Laravel 이미지를 볼 때 404 페이지를 찾을 수 없음

  19. 19

    div 오버레이로 인해 버튼을 클릭 할 수 없음-가능한 Z- 색인 문제

  20. 20

    404 MVC 응용 프로그램을 배포 할 때 찾을 수 없음

  21. 21

    Codeigniter의 경로-404 페이지를 찾을 수 없음

  22. 22

    heroku로 마이그레이션 할 때 장인을 찾을 수 없음

  23. 23

    AngularJS-동일한 URL을 클릭 할 때 페이지를 다시로드 할 수 없습니까?

  24. 24

    버튼을 클릭 할 때 페이지가 새로 고침되는 원인 찾기

  25. 25

    클릭 할 때 두 번째 버튼이나 다른 버튼을 비활성화 할 수 없습니다.

  26. 26

    웹 드라이버를 사용하여 버튼을 클릭 할 수 없음

  27. 27

    버튼을 클릭 할 수 없음-클릭 비활성화

  28. 28

    Switch를 클릭하고 기본 상태로 돌아 가기 위해 클릭 할 때까지 onCheckedChanged에서 버튼을 호출 할 수 없습니다.

  29. 29

    Codeigniter Controller 클래스 로그인 양식 : 404 페이지를 찾을 수 없습니다.

뜨겁다태그

보관