python - redirect reverse in Django -


i'm working on django 1.11

i want redirect user view.

contents of myapp/accounts/urls.py

app_name = 'accounts' urlpatterns = [     url(r'^$', views.profileview.as_view(), name='profile'),     url(r'^profile/', views.profileview.as_view(), name='profile') ] 

and in myapp/accounts/views.py

from django.contrib.auth.models import user  # create views here. django.http import httpresponseredirect django.urls import reverse django.views.generic import templateview, updateview  class profileview(templateview):     template_name = 'accounts/profile.html'  class updateprofile(updateview):     model = user     fields = ['first_name', 'last_name']      template_name = 'accounts/update.html'      def get_object(self):         return self.request.user      def get_success_url(self):         messages.success(self.request, 'profile updated successfully')         return httpresponseredirect(reverse('profile')) 

this giving error on redirect.

noreversematch @ /accounts/update/  reverse 'profile' not found. 'profile' not valid view function or pattern name. 

how redirect user profile page after updating profile details?

how redirect user other app's view?

firstly need give unique names.

urlpatterns = [     url(r'^$', views.profileview.as_view(), name='profile'),     url(r'^profile/', views.profileview.as_view(), name='detailprofile') ] 

now

def get_success_url(self):     messages.success(self.request, 'profile updated successfully')     return reverse('accounts:profile') 

Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -