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 524291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:33:08+00:00 2026-05-13T08:33:08+00:00

I have a problem with django’s MVC. I understand that this is not the

  • 0

I have a problem with django’s MVC. I understand that this is not the traditional MVC, but the documentation emphasizes throughout that it indeed separates presentation from business logic. However, the tutorial comes to a piece of code like this:

def vote(request, poll_id):
    p = get_object_or_404(Poll, id=poll_id)    

    try:
        selected_choice = p.choice_set.get(id=request.POST['choice'])
    except (KeyError, Choice.DoesNotExist):   
        return render_to_response('polls/detail.html', 
                                  { 'poll': p, 'error_message': 'You didn''t select a choice.' } )
    else:
        selected_choice.votes += 1
        selected_choice.save()
        return HttpResponseRedirect(reverse('mysite.polls.views.results', args=(p.id,)))     

    return render_to_response('polls/vote.html', {'poll': p})

(this is maybe not exactly the same as in the tutorial, as it is my implementation, but the concept is the same)

At this part, it handles the request, and (possibly) inserts a record into the database.

Isn’t this wrong? Shouldn’t it be somewhere in the model? What happens in more complex scenarios? Won’t the views get cluttered with lots of db-intensive code, and minimal presentation? Do larger applications have much longer (as in LOC) views?

Edit: This FAQ entry doesn’t answer my question

  • 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-13T08:33:08+00:00Added an answer on May 13, 2026 at 8:33 am

    Nothing is written in stone. In my mind:

    • Views describe what data is to be presented (this is business specific, so it counts as business logic, but not business rules)
    • Models describe data access and business rules (this is where I concentrate most of the domain specific rules about my data)
    • Templates are the display layer, where the data selected in the views is formatted.

    That said, because I rather like the philosophy of lean, simple templates; I sometimes have views doing a lot of masticating of the data to make the work of the templates simpler. I don’t think of that as display code, but I’ve had some people telling me that it is.

    About your example, you say:

    At this part, it handles the request, and (possibly) inserts a record into the database.

    I don’t understand what you mean…

    That view is using the model to create a new record. First it asks for the model to update:

    selected_choice = p.choice_set.get(id=request.POST['choice'])
    

    Then it modifies the model and saves:

    selected_choice.votes += 1
    selected_choice.save()
    

    All the logic about saving (including any overriden save() method) is at the model.

    You have to have code to handle the actions on the models somewhere. Those are the views. They handle looking up data for display and they handle processing requests for modifications.

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

Sidebar

Related Questions

I have an odd problem with Django. I have a set of objects that
I have a problem using the '|default' in django templates. If I do this
I have a problem in customizing labels in a Django form This is the
I don't have this problem on my local development environment, but I just deployed
I have a certain problem with Django forms that seems to me should definitely
I have a problem with python module import. I installed django (this can be
I have this problem: No module named _imagingft I have installed PIL, but it
I have a problem with django-haystack. According to this tutorial I got this apps:
I seem to have similar problem as this guy: Django newbie deployment question -
I have a problem with the jquery-autocomplete pluging and my django script. I want

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.