I have something like this
from django.forms import ModelForm
from django.shortcuts import render_to_response
class ArticleForm(ModelForm):
class Meta:
model = Article
def articl(request):
tykul = ArticleForm()
return render_to_response('test.html',{'tykul':tykul.as_ul()})
And this is a result - name 'Article' is not defined
this same f.ex. for model = Book and others from ModelForm
Why ?
Have you defined an Article model somewhere? Usually it's in models.py in the same folder as your forms.py and views.py, e.g.:
from django.db import models
class Article(models.Model):
title = models.CharField(max_length=100)
text = models.TextField()
Of course, you'll have to import the Article model in your forms.py:
from models import Article
You never imported any classes named Article or Book. They have to be defined in the namespace before they're used.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With