Python “错误”;当前路径user_info/,没有';这些都不匹配。”;
很多用户都问过这个问题,我也尝试过查询中提供的一些解决方案,但这似乎不能解决我的问题,也许我犯了其他错误 我正在尝试创建一个简单的用户注册/登录/注销表单 SchoolnSkill---项目名称,下面是SchoolnSkill/url详细信息:-Python “错误”;当前路径user_info/,没有';这些都不匹配。”;,python,django,Python,Django,很多用户都问过这个问题,我也尝试过查询中提供的一些解决方案,但这似乎不能解决我的问题,也许我犯了其他错误 我正在尝试创建一个简单的用户注册/登录/注销表单 SchoolnSkill---项目名称,下面是SchoolnSkill/url详细信息:- from django.conf.urls import include, url from django.contrib import admin urlpatterns = [ url(r'^admin/', admin.site.url
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^user_info/', include('user_info.urls')),
]
user\u info--应用程序名称,以及user\u info/url详细信息如下:-
from django.conf.urls import url
from . import views
urlpatterns = [
# url(r'^$', views.index, name='index'),
url(r'^registration/', views.UserFormView, name='registration')
]
My views.py输出如下:-
from django.shortcuts import render, redirect
from django.views.generic.edit import CreateView, UpdateView, DeleteView
from django.core.urlresolvers import reverse_lazy
from django.contrib.auth import authenticate, login
from django.views import generic
from .models import Registration
from django.views import View
from .forms import UserForm
class UserFormView(View):
#from_class = UserForm
template_name = 'user_info/registration_form.html'
#dispaly blank form, new user coming to the website
def get(self, request):
form = self.UserForm(None)
return render(request, self.template_name, {'form':form})
def post(self, request):
form = self.UserForm(request.POST)
if form.is_valid():
user = form.save(commit=False)
username = form.cleaned_data['username']
password = form.cleaned_data['password']
user.set_password(password)
user.save()
form.py内容如下:
from django.contrib.auth.models import User
from django import forms
from django.forms import ModelForm
class UserForm(forms.ModelForm):
password = forms.CharField(widget =forms.PasswordInput)
class Meta:
model = User
fields = ['username', 'email', 'password']
我正在使用以下版本:
Python 3.6
Django 1.11.3
Spyder IDE
我很确定我在做一些愚蠢的事情。
请帮忙
以下是错误消息:
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/user_info/
Using the URLconf defined in SchoolnSkill.urls, Django tried these URL patterns, in this order:
^admin/
^user_info/ ^registration/ [name='registration']
The current path, user_info/, didn't match any of these.
当您使用基于类的视图时,您需要在url中添加
as\u view
所以
在user\u info
url中将此更改为
urlpatterns = [
url(r'^registration/', views.UserFormView.as_view(), name='registration')
]
当您使用基于类的视图时,您需要在url中添加
as\u view
所以
在user\u info
url中将此更改为
urlpatterns = [
url(r'^registration/', views.UserFormView.as_view(), name='registration')
]
您无法获得像/user\u info/这样的url,因为您尚未为此定义任何内容,第一个url已被注释掉,因此您需要转到/user\u info/registration/以获取注册页面OK,因此在使用user\u info/registration时会有一些更改。但是我得到了属性错误,这是可以理解的。我已经完成了这个问题。非常感谢。您无法获得像/user\u info/这样的url,因为您尚未为此定义任何内容,第一个url已被注释掉,因此您需要转到/user\u info/registration/以获取注册页面OK,因此我使用user\u info/registration时会有一些更改。但是我得到了属性错误,这是可以理解的。我已经完成了这个问题。非常感谢。。