django 404页面未找到(404)错误请求方法:GET

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

点击此链接时:http://127.0.0.1:8000/accounts/register它给出了404错误,我不知道该怎么办 这是代码:

注册/urls.py:

from django.contrib.auth import views as auth_views
from django.urls import path
from . import views

urlpatterns = [
    path('/register', views.register, name='register'),
]

注册/views.py:

from django.shortcuts import render
from django.contrib.auth import login, authenticate
from django.shortcuts import render, redirect
from .forms import RegistrationForm
from django.shortcuts import render, redirect


def sign_up(request):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            user = form.save()
            login(request, user)
            return redirect('home')
        else:
            form = RegistrationForm()
            return render(request, 'registration/register.html', {'form': form})


def register():
    print("hello!")

urls.py(在项目本身中):

from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static
from django.contrib.auth import views as auth_views
from django.urls import path

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('main.urls')),
    path('news/', include('news.urls')),
    path('accounts/', include('django.contrib.auth.urls')),
]

urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

我尝试了很多 YouTube 视频和文档,但一切都是均匀的

python django url django-urls
1个回答
0
投票
  • 我没有达到 50 声望来评论

在你的 urls.py 上,如果你放了

urlpatterns = [
    path('/register', views.register, name='register'), ]

并使用类似的东西

urlpatterns = [
    path('register/', views.register, name='register'), ] 

我认为这是错误,我不是 django 最专家

© www.soinside.com 2019 - 2024. All rights reserved.