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

  • Home
  • SEARCH
  • 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 6808809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:00:05+00:00 2026-05-26T20:00:05+00:00

I have some problem to figure out how new django views (template view) and

  • 0

I have some problem to figure out how new django views (template view) and forms can works I also can’t find good resources, official doc don’t explain me how can get request ( I mean get and post) and forms in new django views class

Thanks

added for better explain

for example I have this form :

from django import forms

class ContactForm(forms.Form):
    subject = forms.CharField(max_length=100)
    message = forms.CharField()
    sender = forms.EmailField()
    cc_myself = forms.BooleanField(required=False)

and this is the code for read and print the form (old fashion way):

def contact(request):
    if request.method == 'POST': # If the form has been submitted...
        form = ContactForm(request.POST) # A form bound to the POST data
        if form.is_valid(): # All validation rules pass
            # Process the data in form.cleaned_data
            # ...
            return HttpResponseRedirect('/thanks/') # Redirect after POST
    else:
        form = ContactForm() # An unbound form

    return render_to_response('contact.html', {
        'form': form,
    })

well my question is how you can do the same thing with template view thanks

  • 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-26T20:00:06+00:00Added an answer on May 26, 2026 at 8:00 pm

    I would recommend just plodding through the official tutorial and I think realization will dawn and enlightenment will come automatically.

    Basically:
    When you issue a request: ”’http://mydomain/myblog/foo/bar”’
    Django will:

    1. resolve myblog/foo/bar to a function/method call through the patterns defined in urls.py
    2. call that function with the request as parameter, e.g. myblog.views.foo_bar_index(request).
    3. and just send whatever string that function returns to the browser. Usually that’s your generated html code.

    The view function usually does the following:

    1. Fill the context dict for the view
    2. Renders the template using that context
    3. returns the resulting string

    The template generic view allows you to skip writing that function, and just pass in the context dictionary.

    Quoting the django docs:

    from django.views.generic import TemplateView
    
    class AboutView(TemplateView):
        template_name = "about.html"
    

    All views.generic.*View classes have views.generic.View as their base. In the docs to that you find the information you require.
    Basically:

    # urls.py
    urlpatterns = patterns('',
            (r'^view/$', MyView.as_view(size=42)),
        )
    

    MyView.as_view will generate a callable that calls views.generic.View.dispatch()
    which in turn will call MyView.get(), MyView.post(), MyView.update() etc.
    which you can override.

    To quote the docs:

    class View

    dispatch(request, *args, **kwargs)

    The view part of the view — the method that accepts a request
    argument plus arguments, and returns a HTTP response. The default
    implementation will inspect the HTTP method and attempt to delegate to
    a method that matches the HTTP method; a GET will be delegated to
    get(), a POST to post(), and so on.

    The default implementation also sets request, args and kwargs as
    instance variables, so any method on the view can know the full
    details of the request that was made to invoke the view.

    The big plusses of the class based views (in my opinion):

    1. Inheritance makes them dry.
    2. More declarative form of programming
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A simple question I'm sure, but I can't figure it out. I have some
Can't figure out how to resolve following problem: I have a few actors (workers)
i am new in JSP,i have some problem with the following code : <%@
I have following problem. In my view model I defined some list properties as
I am trying to figure out how to tackle this problem. I have to
I have some problem with my code public IQueryable<PageItems> GetPageById(Guid Id) { var xml
I have some problem with Jquery Autocomplete plugin ( http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/ ) I got it
I have some problem with my .htaccess file. Here I am adding my problem.
I have some problem to order an array by a field of this, here
I have some problem whith such mysql_query INSERT INTO table VALUES ('', CURDATE()-1) why

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.