urls.py ------- url(r'^accounts/profile/$', create_profile, { 'profile_callback': UserProfile.objects.create },name='profiles_create_profile'), url(r'^accounts/editprofile/$', edit_profile, name='profiles_edit_profile'), url(r'^accounts/viewprofile/(?P<username>\w+)/$', profile_detail, name='profiles_profile_detail'),
views.py -------- def create_profile(request, form_class=ProfileForm, success_url=None,template_name='registration/profile.html', extra_context=None,profile_callback=None,): try: profile_obj = request.user.get_profile() print "Profile obj : ", profile_obj ###### Profile obj is printing return HttpResponseRedirect(reverse('profiles_edit_profile')) except ObjectDoesNotExist: pass if success_url is None: success_url = reverse('profiles_profile_detail', kwargs={ 'username': request.user.username }) if form_class is None: form_class = utils.get_profile_form() if request.method == 'POST': form = form_class(data=request.POST, files=request.FILES) if form.is_valid(): profile_obj = form.save(request.user) #profile_obj.user = request.user #profile_obj.save() if hasattr(form, 'save_m2m'): form.save_m2m() return HttpResponseRedirect(success_url) else: form = form_class() if extra_context is None: extra_context = {} context = RequestContext(request) for key, value in extra_context.items(): context[key] = callable(value) and value() or value return render_to_response(template_name, { 'form': form }, context_instance=context) create_profile = login_required(create_profile) ############ Edit Profile view ############## def edit_profile(request, form_class=None, success_url=None, template_name='registration/edit_profile.html', extra_context=None): try: profile_obj = request.user.get_profile() print "edit profile_obj :", profile_obj except ObjectDoesNotExist: return HttpResponseRedirect(reverse ('profiles_create_profile')) if success_url is None: success_url = reverse('profiles_profile_detail', kwargs={ 'username': request.user.username }) if form_class is None: form_class = utils.get_profile_form() if request.method == 'POST': form = form_class(data=request.POST, files=request.FILES, instance=profile_obj) print "Form ; ", form if form.is_valid(): form.save() return HttpResponseRedirect(success_url) else: form = form_class(instance=profile_obj) if extra_context is None: extra_context = {} context = RequestContext(request) for key, value in extra_context.items(): context[key] = callable(value) and value() or value return render_to_response(template_name, { 'form': form, 'profile': profile_obj, }, context_instance=context) edit_profile = login_required(edit_profile) ######### detail view of profile ########## def profile_detail(request, username, public_profile_field=None, template_name='registration/profile_list.html', extra_context=None): user = get_object_or_404(User, username=username) try: profile_obj = user.get_profile() profile_model = utils.get_profile_model() print "Profile Model :", profile_obj except ObjectDoesNotExist: raise Http404 if public_profile_field is not None and \ not getattr(profile_obj, public_profile_field): profile_obj = None if extra_context is None: extra_context = {} context = RequestContext(request) for key, value in extra_context.items(): context[key] = callable(value) and value() or value return render_to_response(template_name, { 'profile_obj': profile_obj }, context_instance=context) profile.html ------------ <form action="{% url profiles_create_profile %}" method="POST"> <input type="submit" value="Create profile" /> </form> edit_profile.html ----------------- <form action="{% url profiles_profile_detail user.username %}" method="POST"> <input type="submit" value="Save profile" /> </form> profile_list.html -------------------- <form action="{% url profiles_create_profile %}" method="POST"> this work but do not save altered value to database and i tried with this too <form action="{% url profiles_edit_profile %}" method="POST"> i get errors " this field is required" <input type="submit" value="Edit profile" /> </form> Very first time if user have not created profile then account/profile will redirect you to profile.html and will let you to save the profile. if the user come back or write in browser accounts/profile then it will redirect you to accounts/editprofile(user have already profile) with edit_profile.html and all fields display the same value as he enetered first time while creating the profile now suppose he change the gender Male to Female and save profile then it takes you to view profile but in view profile i still get gender female(because that form is GET method not paste method) and the scond problem if i am in view profile and want to edit my profile by clicking on 'Edit Profile' and i am trying to reach to edit profile page with POST method through view profile then i get 'Field error value this field is required'.. see in profile_list.html. This all thing is happening cause of GET and POST method. i do not know how to resolve? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---