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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:24:17+00:00 2026-06-14T12:24:17+00:00

I’m developing an app with django, and I have a view where I use

  • 0

I’m developing an app with django, and I have a view where I use 2 return render_to_response, with two different html files, depending on the status of the user.

I was wondering if it would be a better practice to split my view into two different views or if I should keep a bigger view.

What are the pros and the cons of doing so?

Sorry if my question is not clear. Thank you very much for your advices.

  • 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-06-14T12:24:18+00:00Added an answer on June 14, 2026 at 12:24 pm

    There’s no right or wrong answer to this question so your question may not be acceptable on stackoverflow, which usually is intended for questions/problems with specific technical solutions.

    That said, here’s my view on this topic – I personally like to keep my view function small and if further processing is required, split them out into smaller functions.

    For example:-

    @permission_required('organizations.organization_add_user')
    def organization_add_user(request, org_slug):
        org = get_object_or_404(Organization, slug=org_slug)
        form = OrganizationAddUserForm(org=org)
    
        if request.method == 'POST':
            form = OrganizationAddUserForm(request.POST or None, request.FILES or None, org=org)
            if form.is_valid():
                cd = form.cleaned_data
    
                # Create the user object & send out email for activation
                user = create_user_from_manual(request, data=cd)
    
                # Add user to OrganizationUser
                org_user, created = OrganizationUser.objects.get_or_create(user=user,\
                                                                        organization=org)
                dept = org.departments.get(name=cd['department'])
                org_user.departments.add(dept)
    
                # Add user to the appropriate roles (OrganizationGroup) and groups (django groups)
                org_groups = OrganizationGroup.objects.filter(group__name__in=cd['roles'], \
                    organization=org)
                for g in org_groups:
                    user.groups.add(g.group)
    
                return HttpResponse(reverse('add_user_success'))
    
        template = 'organizations/add_user.html'
        template_vars = {'form': form}
        # override request with dictionary template_vars
        template_vars = FormMediaRequestContext(request=request, dict=template_vars)
        return render(request, template, template_vars)
    

    FormMediaEquestContext is a class I import from another file and has its own logic which helps me to handle javascript and css files associated with my form (OrganizationAddUserForm).

    create_user_from_manual is yet another function which is encapsulated separately and deals with the reasonably convolutated logic relating to creating a new user in my system and sending an invitation email to that new user.

    And of course, I serve up a different template if this is the first time a user arrives on this “add user” page as opposed to redirecting to a completely different url with its own view function and template when the add user form is successfully executed.

    By keeping our view functions reasonably small, I have an easier time tracking down bugs relating to specific functionality.

    In addition, it is also a good way to “reuse” my utility functions such as the create_user_from_manual method should I need this same utility function in another view function.

    However, at the end of the day, organizing code and encapsulating code is a judgement call that you get to make as you progress as a developer.

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

Sidebar

Related Questions

I have thousands of HTML files to process using Groovy/Java and I need to
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I've tracked down a weird MySQL problem to the two different ways I was
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a bunch of posts stored in text files formatted in yaml/textile (from
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.