"removedindjango18warning: creating a modelform without either the 'fields' attribute or the 'exclude' attribute is deprecated" Code Answer

4

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.

By tharun on July 12 2022

Answers related to “removedindjango18warning: creating a modelform without either the 'fields' attribute or the 'exclude' attribute is deprecated”

Only authorized users can answer the Search term. Please sign in first, or register a free account.