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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:59:49+00:00 2026-05-22T02:59:49+00:00

This is what I am doing at the moment: views.py def activation_signupcount(request): if request.method

  • 0

This is what I am doing at the moment:

views.py

def activation_signupcount(request):

    if request.method == 'POST':

        return render_to_response('activation_signupcount.html', 
                                {   'datestart': request.POST['datestart'], 
                                    'dateend': request.POST['dateend'], 
                                    'usersegment': request.POST['usersegment'], 
                                    'segment_form': SegmentForm(request.POST), 
                                    'date_form': DateSelectForm(request.POST)    })
    else:

        return render_to_response('activation_signupcount.html', 
                                {'segment_form': SegmentForm(), 'date_form': DateSelectForm()})

template

{% extends "base_activation.html" %}

{% block content %}
    <h2>Sign ups</h2>
    <p>Number of users who have registered to the site between the dates entered</p>
{% endblock %}

{% block graph %}
    {% if datestart %}
    <p>This counts the number of <strong>{{ usersegment }}</strong> users who have successfully registered to the site (verified their email)
    who joined between <strong>{{ datestart }}</strong> and <strong>{{ dateend }}</strong></p>
    <img src="./activation_signupcount.png?usersegment={{ usersegment }}&datestart={{ datestart }}&dateend={{ dateend }}" />
    {% endif %}
{% endblock %}

So I am returning the same page when a user submits the SegmentForm and DateSelectForms. To check if I should return the output (a graph), I am checking for the existence of datestart as seen in my template {% if datestart %} if it was submitted.

Is this a Djangoic way of doing it? I feel I ought to be checking for response == 'POST' rather than forcing the check variable to datestart.

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-22T02:59:49+00:00Added an answer on May 22, 2026 at 2:59 am

    First, a few pointers to save you headaches when debugging the code. Instead of testing for request.method == ‘POST’, check whether the value you have attached to the submit button on your form(s) (in the template) is in the request.POST dictionary. I’m not sure whether you are submitting 2 forms with one “submit”-button, but if you do, why not write one form for it?

    Also, always check whether your form is valid. This saves you a lot of headaches when rendering your graph, as the code for the graph can then safely make certain assumptions about the quality of the data it receives. Also, the user will know why the graph doesn’t render (he’ll get error messages in his form).

    You could make the validation check in the template or in the view (the latter is recommended – program logic should reside in your views). If your forms are valid, they will get the “cleaned_data” properties, containing the validated data.

    Off the top of my head, here’s what more Django-ic code would look like:

    def render_view(request):
        if "submit" in request.POST: # Supposing both forms are submitted with one "submit" button
            segment_form = SegmentForm(request.POST)
            dateselect_form = DateSelectForm(request.POST)
        else:
            segment_form = SegmentForm()
            dateselect_form = DateSelectForm()
    
        return render_to_response('activation_signupcount.html',{'segment_form': segment_form, 'date_form': date_form, 'display_graph': (segment_form.is_valid() and dateselect_form.is_valid())})
    

    Then, in your template, first check if the forms are valid (the ‘display_graph’ variable is True if both forms are valid), and then access their cleaned_data properties to get the values you want. For instance:

    {% block graph %}
    {% if display_graph %}
        <p>This counts the number of <strong>{{ segment_form.cleaned_data.usersegment }}</strong> users who have successfully registered to the site (verified their email)who joined between <strong>{{ date_form.cleaned_data.datestart }}</strong> and <strong>{{ date_form.cleaned_data.dateend }}</strong></p>
    <img src="./activation_signupcount.png?usersegment={{ segment_form.cleaned_data.usersegment }}&datestart={{ date_form.cleaned_data.datestart }}&dateend={{ date_form.cleaned_data.dateend  }}" />
    {% endif %}
    {% endblock %}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im doing this project where i need to download files through a webservice (images,
This is my first time doing this sort of project so apologies if the
I'm doing this system Stacked and I am creating the search function. And in
I am doing this in groovy. Input: hip_abc_batch hip_ndnh_4_abc_copy_from_stgig abc_copy_from_stgig hiv_daiv_batch hip_a_de_copy_from_staging abc_a_de_copy_from_staging I
I am doing this: <div onclick='alert("xxx")'>Click me!</div> and I see that alert but I
I am doing this with the following: [[self navigationController] setNavigationBarHidden:YES animated:YES]; and also I
I am doing this: @person.attributes = params[:person] Can anyone give me a clue as
I'm doing this query: SomeObject.objects.annotate(something=Avg('something')).order_by(something).all() I normally have an aggregate field in my model
I tried doing this: [toolbar setTint:[UIColor colorWithPatternImage:[UIImage imageNamed:@thingFromMyBundle.png]]]; but it just ended up black.
I am doing this small exercise. declare @No decimal(38,5); set @No=12345678910111213.14151; select @No*1000/1000,@No/1000*1000,@No; Results

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.