views:

200

answers:

1

I want to learn how can I add to template to my ModelForm i'm newbie. Below you can see my models.py, url.py and views.py:

My model.py looks like that:

from django.db import models

from django.forms import ModelForm

from django.contrib.auth.models import User


class Yazilar(models.Model):

    yazi = models.CharField(max_length=200)

    temsilci = models.ForeignKey(User)


class YaziForm(ModelForm):   

class Meta: 

 model = Yazilar


My views.py function is below:


@login_required

def yazi_ekle(request):

        yazim = YaziForm

        return render_to_response('yazi/save.html', {'YaziForm': YaziForm})

My url.conf looks like below:

(r'^yazi/save/$', 'tryout.yazi.views.yazi_ekle'),

My question is about creating a form and what is that forms "action" parameter?

A: 

You could in fact use <form action=""> since the url you want to post to is the same as the page you are on.

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:

<form action="{{ request.path }}">

As always, see the docs :)

http://docs.djangoproject.com/en/1.1/ref/request-response/#django.http.HttpRequest.path

Anentropic