Richard Dahl wrote:
> It is hard to see with the indentation as it is, but it
seems you are
> not returning an http response if the 'if id is none:'
You are
> building the form for model, but it doesnt look like it
is returned.
> The bottom line seems to be indented to correlate to
the if
> request.method not the first if.
>
thks - you are exactly right - I fixed the indentation and
all is well.
>
> -richard
>
> On Sep 27, 2007, at 10:52 PM, staff-gmail wrote:
>
>
>> I tried the following but it fails in flames with
"http response
>> required..." I've followed the documentation
- am I called the
>> function correctly by a url with
"/mymodel_addedit" Can someone
>> help ?
>>
>> urls.py
>> r'^mymodel/addedit/$',
'myproject.myapp.views.mymodel_addedit'),
>>
>> views.py
>> def mymodel_addedit(request, id=None):
>> if id is None:
>> MyModelForm =
forms.models.form_for_model(MyModel)
>> else:
>> mymodel = MyModel.objects.get(id=id)
>> MyModelForm =
forms.models.form_for_instance(mymodel)
>> if request.method == 'POST':
>> form = MyModelForm(request.POST)
>> if form.is_valid():
>> mymodel = form.save(commit=False)
>> mymodel.save()
>> return HttpResponseRedirect("/")
>> else:
>> form = MyModelForm()
>> return render_to_response('mymodel_addedit.html',
{'form': form})
>>
>> /templates/mymodel_addedit.html
>> {% extends "base.html" %}
>>
>> {% block content %}
>> <form action="."
method="post">
>> <table class="form">
>> {}
>> </table>
>> <input type="submit"
value="Submit" />
>> </form>
>> {% endblock %}
>>
>>
>>
>
>
> >
>
>
--~--~---------~--~----~------------~-------~--~----~
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-unsubscribe googlegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
|