Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You could in fact use <code>&lt;form action=""&gt;</code> since the url you want to post to is the same as the page you are on.</p> <p>If you don't like that then as long as you have 'django.core.context_processors.request' in your TEMPLATE_CONTEXT_PROCESSORS in settings.py I think you could also do:</p> <pre><code>&lt;form action="{{ request.path }}"&gt; </code></pre> <p>As always, see the docs :)</p> <p><a href="http://docs.djangoproject.com/en/1.1/ref/request-response/#django.http.HttpRequest.path" rel="nofollow noreferrer">http://docs.djangoproject.com/en/1.1/ref/request-response/#django.http.HttpRequest.path</a></p> <h2>EDIT</h2> <p>In case, in the intervening year since this question was posted, the poster still hasn't tried to read the ModelForm docs... <a href="http://docs.djangoproject.com/en/1.2/topics/forms/modelforms/" rel="nofollow noreferrer">http://docs.djangoproject.com/en/1.2/topics/forms/modelforms/</a></p> <p>Yes the view is wrong, you have instantiate the form. You also want some logic to handle the post data. If it's an edit view you probably also want the view to take an item id in the view args and have some logic to load that model instance.</p> <p>eg:</p> <pre><code>@login_required def yazi_ekle(request, id=None): form_args = {} if id is not None: # edit an existing Yazilar try: yazilar = Yazilar.objects.get(pk=id) except Yazilar.DoesNotExist: return Http404('Yazilar not found') form_args['instance'] = yazilar # else create new Yazilar... if request.POST: form_args['data'] = request.POST yazi_form = YaziForm(**form_args) if yazi_form.is_valid(): yazilar = yazi_form.save(commit=True) else: yazi_form = YaziForm(**form_args) return render_to_response('yazi/save.html', { 'yazi_form': yazi_form }, context_instance=RequestContext(request) ) </code></pre> <p>then in your urls.py something like:</p> <pre><code>(r'^yazi/ekle/(?P&lt;id&gt;\d+)?$', 'tryout.yazi.views.yazi_ekle'), </code></pre> <p>and in the template:</p> <pre><code>&lt;form method="post" action=""&gt; {% csrf_token %}&lt;!-- required since Django 1.2 or later --&gt; &lt;ul&gt; {{ yazi_form.as_ul }} &lt;/ul&gt; &lt;input type="submit" value="Submit Form"/&gt; &lt;/form&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload