How can I link an edit page to my detail profile page in django? -
so trying link template can edit user_profile this:
edit
but giving me error:
noreversematch @ /user_profile/9/ reverse 'user_profile_update' arguments '()' , keyword arguments '{u'id': ''}' not found. 1 pattern(s) tried: [u'user_profile/(?p\d+)/edit/$']
but can access template without error: /user_profile/(id)/edit
this view:
def user_profile_update(request, id=none): instance = get_object_or_404(user_profile, id=id) form = user_profileform(request.post or none, request.files or none, instance=instance) if form.is_valid(): instance = form.save(commit=false) instance.save() return httpresponseredirect(instance.get_absolute_url()) context = { "first_name": instance.first_name, "instance": instance, "form":form, } return render(request, "user_profile/user_profile_form.html", context)
this url:
url(r'^create/$', user_profile_create,name='create'), url(r'^(?p<id>\d+)/$', user_profile_detail, name='detail'), url(r'^(?p<id>\d+)/edit/$',user_profile_update, name='edit'), url(r'^(?p<id>\d+)/delete/$', user_profile_delete),
and model:
class user_profile(models.model): first_name = models.charfield(null=true,max_length=100) last_name = models.charfield(null=true,max_length=100) address_1 = models.charfield(_("address"), max_length=128) address_2 = models.charfield(_("address 1"), max_length=128, blank=true) city = models.charfield(_("city"), max_length=64, default="pune") country_name = models.charfield(max_length=60) pin_code = models.charfield(_("pin_code"), max_length=6, default="411028") updated = models.datetimefield(auto_now=true, auto_now_add=false) timestamp = models.datetimefield(auto_now=false, auto_now_add=true) def __unicode__(self): return self.first_name def __str__(self): return self.first_name def get_absolute_url(self): return reverse("user_profile:detail", kwargs={"id": self.id}) class meta: ordering = ["-timestamp", "-updated"]
i glad if me!
you need separate views , url-conf editing , detail view. have ^user_profile/(?p\d+)/edit/$'
in url-conf, can access view user_profile/123/edit/
. need add url '^user_profile/(?p\d+)/$
access user_profile/123/
.
same views, need 2 separate ones simplest solution.
Comments
Post a Comment