在django中将用户名添加到url

时间:2016-09-03 21:24:13

标签: python django url

我一直在尝试添加系统的网址,并在其中添加用户名作为参数,但它对我不起作用,我在这里看到了一些评论但它不起作用我这样做他们已经完成或解决了他们的问题。

views.py

@login_required
def profile(request, username):
    User = get_object_or_404(user, username=username)
    return render(request, 'dashboard/Profile.html', {'profile': User})

urls.py

url(r'^profile/(?P<username>\w+)/$', views.profile, name='profile'),

如果需要,这是我的forms.py

class RegistrationForm(forms.Form):
    username = forms.RegexField(regex=r'^\w+$', widget=forms.TextInput(attrs=     {'class': 'form-control'}),
    label=_("Username"), error_messages={'invalid': _("This value must be contain only letters, number and undescores.!")})
    email = forms.EmailField(widget=forms.TextInput(attrs={'class': 'form-control'}), label=_("Email Address"))
    password1 = forms.CharField(widget=forms.PasswordInput(attrs={'class': 'form-control'}), label=_("Type your password"))
    password2 = forms.CharField(widget=forms.PasswordInput(attrs={'class': 'form-control'}), label=_("Retype your password"))

This is the error that the system shows me

I tried with these posts and it does not work for me.

0 个答案:

没有答案