119👍
For your form, it’s a warning, not an error, telling you that in django 1.8, you will need to change your form to
from django import forms
from models import Article
class ArticleForm(forms.ModelForm):
class Meta:
model = Article
fields = '__all__' # Or a list of the fields that you want to include in your form
Or add an exclude
to list fields to exclude instead
Which wasn’t required up till 1.8
https://docs.djangoproject.com/en/1.8/topics/forms/modelforms/#selecting-the-fields-to-use
As for the error with your views, your return is inside of an if
statement: if request.POST:
so when it receives a get request, nothing is returned.
def create(request):
if request.POST:
form = ArticleForm(request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect('/articles/all')
else:
form = ArticleForm()
args = {}
args.update(csrf(request))
args['form'] = form
return render_to_response('create_article.html', args)
Just dedent the else
block so that it’s applying to the correct if
statement.
10👍
You just need…
from django import forms
from models import Article
class ArticleForm(forms.ModelForm):
class Meta:
model = Article
exclude = ()
…to fix your form. You’ll need to post your view code to see what’s up with that.
- [Django]-How to stream an HttpResponse with Django
- [Django]-How to get Request.User in Django-Rest-Framework serializer?
- [Django]-Django.db.utils.ProgrammingError: relation "bot_trade" does not exist
6👍
if you use fields = __all__
as Ngenator suggested, and if it’s a project that might have to run under various versions of Django, the following conditional will be needed:
if django.VERSION >= (1, 6):
fields = '__all__' # eliminate RemovedInDjango18Warning
otherwise you get the error django.core.exceptions.FieldError: Unknown field(s) (a, l, _) specified for CrispyTestModel
, as seen here: https://travis-ci.org/maraujop/django-crispy-forms/jobs/56996180
- [Django]-How to properly use the "choices" field option in Django
- [Django]-You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application
- [Django]-Django: how can I tell if the post_save signal triggers on a new object?
2👍
In your view, you don’t return anything if the request is not a POST. You should move everything from the else
statement onwards back one indent.
- [Django]-Python 3 list(dictionary.keys()) raises error. What am I doing wrong?
- [Django]-Performing a getattr() style lookup in a django template
- [Django]-For what purpose Django is used for?