Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7564553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:56:13+00:00 2026-05-30T13:56:13+00:00

Django 1.3 documentation on class based views is seeming like a treasure hunt. How

  • 0

Django 1.3 documentation on class based views is seeming like a treasure hunt. How to write the class is clear enough… but what kind of template code matches each generic class? Would someone provide a complete example soup to nuts? Here’s what I have so far:

urls.py

(r'^brand_create2$',    BrandCreate.as_view()),

views.py

from django.views.generic import CreateView
@login_required
class BrandCreate(CreateView):
    template_name       = 'generic_form_popup.html'
    context_object_name = "brand_thingie"
    #queryset            = models.Brand.objects.all()
    success_url         = '/'

generic_form_popup.html

????

In this case I’m exploring if it is worth learning the new style, given the older style still works:

urls.py

url(r'^brand_create1$', 'coat.views.brand_create'),

views.py

class formBrand(forms.ModelForm):
    class Meta:
        model = models.Brand
        exclude = ('')

@login_required
def brand_create(request):

    form = formBrand
    if request.method == 'POST':
        form = formBrand(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/')

    passed = dict(
        form=form,
        MEDIA_URL  = settings.MEDIA_URL,
        STATIC_URL = settings.STATIC_URL)
    return render_to_response('generic_form_popup.html',
    passed, context_instance=RequestContext(request))

generic_form_popup.html

{% extends 'head-plain.html' %}
{% block title %}{% endblock %}
{% block headstuff %}{% endblock %}
{% block content %}   
<form action="{{ action }}" method="post">
{% csrf_token %}{{ form.as_p }}
<input type="submit" value="Submit" /> </form>    
{% endblock %}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T13:56:13+00:00Added an answer on May 30, 2026 at 1:56 pm

    CreateView inherits from ModelFormMixin, which in turn inherits from FormMixin and SingleObjectMixin.

    SingleObjectMixin provides the object template context variable, which is probably not going to be any use in the case of CreateView:

    object: The object that this view is displaying. If context_object_name is specified, that variable will also be set in the context, with the same value as object.

    But FormMixin provides the form context variable:

    form: The form instance that was generated for the view.

    Thus, you can refer to the documentation to display a form with a template:

    <form action="/contact/" method="post">{% csrf_token %}
    {{ form.as_p }}
    <input type="submit" value="Submit" />
    </form>
    

    Which means that the very template you posted should almost work with the class based view:

    {% extends 'head-plain.html' %}
    {% block title %}{% endblock %}
    {% block headstuff %}{% endblock %}
    {% block content %}   
    <form action="" method="post">
    {% csrf_token %}{{ form.as_p }}
    <input type="submit" value="Submit" /> </form>    
    {% endblock %}
    

    I removed {{ action }} because it is not part of the context, neither in the old-style view, neither with the class based view, so it doesn’t make any sense. You should know that if action=”” then the browser will submit to the current url. You can force the action to the current url with action=”{{ request.path }}” or you can specify another url with the url template tag.

    Suppose apply the best practice of naming url patterns, by changing:

    (r'^brand_create2$',    BrandCreate.as_view()),
    

    to:

    (r'^brand_create2$',    BrandCreate.as_view(), name='band_create'),
    

    Then you can use: action="{% url band_create %}".

    You can also customize further:

    <form action="/contact/" method="post">
        {% csrf_token %}
        {{ form.non_field_errors }}
        <div class="fieldWrapper">
            {{ form.subject.errors }}
            <label for="id_subject">Email subject:</label>
            {{ form.subject }}
        </div>
        <div class="fieldWrapper">
            {{ form.message.errors }}
            <label for="id_message">Your message:</label>
            {{ form.message }}
        </div>
        <div class="fieldWrapper">
            {{ form.sender.errors }}
            <label for="id_sender">Your email address:</label>
            {{ form.sender }}
        </div>
        <div class="fieldWrapper">
            {{ form.cc_myself.errors }}
            <label for="id_cc_myself">CC yourself?</label>
            {{ form.cc_myself }}
        </div>
        <p><input type="submit" value="Send message" /></p>
    </form>
    

    Of course, the fields available in the form depend on your Model.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to write joins in django,i have gone through below django documentation ,but joins
WIth class-based views having become MUCH better in Django, I am running into a
I've seen some nifty code on django-ratings documentation and like to create something similar.
I am having problems using django-tagging . I try to follow the documentation but
Django's internationalization is very nice (gettext based, LocaleMiddleware), but what is the proper way
This example is from the Django documentation . Given the (Django) database model: class
I'm creating custom template tags for my django site. I've followed the django documentation
i am learning django but gave web.py a try first. while reading django's documentation
I was looking over the Django documentation on a way to do this but
There's no much documentation on how to deploy a Django project with Spawning and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.