简体   繁体   English

未找到页面 (404) 请求方法:GET 请求 URL:http://127.0.0.1:8000/accounts/signup in DJANGO 即使 url 已正确映射

[英]Page not found (404) Request Method: GET Request URL: http://127.0.0.1:8000/accounts/signup in DJANGO even though urls is mapped correctly

Below is the urls.py file of sub-app accounts下面是子应用账号的urls.py文件

from django.urls import path
from . import views 

urlpatterns = [
    path("signup",views.signup,name='signup')
   
]

This views.py of accounts这个views.py of accounts

def signup(request):
    if request.method == 'POST':

        firstname = request.POST['first_name']
        lastname = request.POST['last_name']
        username = request.POST['username']
        password1 = request.POST['password1']
        password2 = request.POST['password2']
        email = request.POST['email']

        if password1==password2:
                user = User.objects.create_user(firstname =first_name ,lastname =last_name ,username =username , email=email, password=password1)
                user.save();
                print("USER CREATED SUCCESSFULLY")
                return redirect('login.html')
    else:
        return redirect('signup.html')

I have even mapped the url in main url.py also, but still it is showing error.我什至在主 url.py 中映射了 url,但它仍然显示错误。 below is the signup.html下面是注册.html

The signup.html file signup.html文件

<form action="signup" method="POST">
            {% csrf_token %}
            <input type="text" name="first_name" placeholder="FIRST NAME"><br>
            <input type="text" name="last_name" placeholder="LAST NAME"><br>
            <input type="text" name="username" placeholder="USERNAME"><br>
            <input type="email" name="email" placeholder="EMAILID"><br>
            <input type="password" name="password1" placeholder="PASSWORD"><br>
            <input type="password" name="password2" placeholder="CONFIRM PASSWORD"><br>
            <input type="submit">

can anyone please help me out with this problem, i am not getting what went wrong.谁能帮我解决这个问题,我没有弄错。 It is displaying page not found error.它显示页面未找到错误。

you need to include accounts.urls in project urls.py (ie,) which folder contains settings.py您需要在项目 urls.py 中包含 accounts.urls (即)哪个文件夹包含 settings.py

for example: let i am assumed that you create project Todo例如:假设您创建了项目 Todo

Todo    
 - accounts
    - __init__.py
    - models.py
    - urls.py
    - views.py
    - apps.py
    - tests.py

 - Todo
    - __init__.py
    - urls.py
    - wsgi.py
    - settings.py

Todo/urls.py you need to include accounts.urls Todo/urls.py 你需要包含 accounts.urls

from django.conf.urls import include, path
app_name = "Todo"

urlpatterns = [
    # Examples:
     path(r'^accounts/', include('accounts.urls', namespace="Account")),
]

you need to accounts apps in file settings.py application definition list您需要在文件settings.py应用程序定义列表中记录应用程序

# Application definition

INSTALLED_APPS = [
    'accounts',
     ......
    'django.contrib.auth',
]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 页面未找到 (404) 请求方法:POST 请求 URL:http://127.0.0.1:8000/accounts/signup/signup - Page not found (404) Request Method: POST Request URL: http://127.0.0.1:8000/accounts/signup/signup Django 错误:找不到页面 (404) 请求方法:GET 请求 URL:http://127.0.0.1:8000/helpdesk/login/?next=/ - Django Error: Page not found (404) Request Method: GET Request URL: http://127.0.0.1:8000/helpdesk/login/?next=/ 找不到页面(404)请求方法:GET请求URL:http://127.0.0.1:8000/hello - Page not found (404) Request Method: GET Request URL: http://127.0.0.1:8000/hello 页面未找到 (404) 请求方法:GET 请求 URL:http://127.0.0.1:8000/admin - Page not found (404) Request Method: GET Request URL: http://127.0.0.1:8000/admin 找不到页面(404)请求方法:GET请求URL:http://127.0.0.1:8000 - Page not found (404) Request Method: GET Request URL: http://127.0.0.1:8000 找不到页面(404)请求方法:GET请求URL:http://127.0.0.1:8000/about - Page not found (404) Request Method: GET Request URL: http://127.0.0.1:8000/about 找不到页面 (404) 请求方法:GET 请求 URL: http://127.0.0.1:8000/login - Page not found (404) Request Method: GET Request URL: http://127.0.0.1:8000/login 页面未找到 (404) 请求方法:GET 请求 URL:http://127.0.0.1:8000/contacts/contact.html - Page not found (404) Request Method: GET Request URL: http://127.0.0.1:8000/contacts/contact.html 找不到页面(404)请求方法:GET请求URL:http://127.0.0.1:8000/catalog/ - Page not found (404) Request Method: GET Request URL: http://127.0.0.1:8000/catalog/ 找不到页面 (404) 请求方法:POST 请求 URL:http://127.0.0.1:8000/login/login1 - Page not found (404) Request Method: POST Request URL: http://127.0.0.1:8000/login/login1
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM