#Reverse for 'user_profile_view' with arguments '(u'Emmanuel',)' and keyword arguments '{}' not found. 0 pattern(s) tried: [] :
#project/urls.py:
from django.conf.urls import url, include
from django.contrib import admin
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^accounts/', include('registration.backends.default.urls')),
url(r'', include('app.urls', namespace='app')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
#app/urls.py
from .views import *
from . import views
from django.conf import settings
from django.conf.urls import url
from django.views.generic import TemplateView
from django.conf.urls.static import static
app_name = 'app'
urlpatterns = [
url(r'^$', views.IndexView.as_view(), name='index'),
url(r'^accounts/home_page/$', home_page),
url(r'^accounts/home_page/(?P<username>[\w-]+)/$', UserProfileView.as_view(), name='user_profile_view'),
# url(r'^accounts/profile/$', views.user_profile, name='user_profile'),
# url(r'^accounts/profile/edit/$', views.edit_user_profile,
# name='edit_user_profile'),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
#views.py
class UserProfileView(View):
@method_decorator(login_required)
def get(self, request, user):
if request.user.username == user:
profile = get_object_or_404(User, user=request.user)
return render(request, 'registration/home.html', {'profile': profile})
else:
raise Http404
@login_required
def home_page(request):
return HttpResponseRedirect(
reverse('user_profile_view', args=[request.user.username], current_app='app'))
所以我实际上要做的是允许一个用户名出现在url中的用户登录,但是由于登录名是REDIRECT,url='/accounts/home\u page'不能像我使用重定向一样使用动态参数。但是我犯了这个错误,请问我做错了什么。 提前谢谢!!!你知道吗
所以当我跟着@ShanWang说我得到了错误时,我改变了答案:
TypeError异常值:get()得到意外的关键字参数“username” 因为我的
def get(self, request, username):
是def get(self, request, user):
,所以我改变了这个至
成功了
相关问题 更多 >
编程相关推荐