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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:34:01+00:00 2026-05-14T04:34:01+00:00

I am trying to come up with a form that lets the user select

  • 0

I am trying to come up with a form that lets the user select a date range to generate a web query in Django. I am having errors getting the date to filter with in my view, I am unable to strip the date.

Here is my forms.py:

class ReportFiltersForm(forms.Form):
    start_date = forms.DateField(input_formats='%Y,%m,%d',widget=SelectDateWidget())
    end_date = forms.DateField(input_formats='%Y,%m,%d',widget=SelectDateWidget())

And my view

if request.method == 'POST':
    form = ReportFiltersForm(request.POST)
    sdy = request.POST['start_date_year']
    sdm = request.POST['start_date_month']
    sdd = request.POST['start_date_day']
    edy = request.POST['end_date_year']
    edm = request.POST['end_date_month']
    edd = request.POST['end_date_day']
    start_date= datetime.date(sdy, sdm, sdd)
    end_date= datetime.date(edy, edm,edd)

Traceback

Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/django/core/servers/basehttp.py", line 651, in __call__
return self.application(environ, start_response)
File "/usr/lib/python2.6/site-packages/django/core/handlers/wsgi.py", line 241, in __call__
response = self.get_response(request)
File "/usr/lib/python2.6/site-packages/django/core/handlers/base.py", line 134, in get_response
return self.handle_uncaught_exception(request, resolver, exc_info)
File "/usr/lib/python2.6/site-packages/django/core/handlers/base.py", line 154, in handle_uncaught_exception
return debug.technical_500_response(request, *exc_info)
File "/usr/lib/python2.6/site-packages/django/core/handlers/base.py", line 92, in get_response
response = callback(request, *callback_args, **callback_kwargs)
File "/home/projects/acms/cms/views.py", line 470, in eventreports
start_date= datetime.date(sdy, sdm, sdd)
TypeError: an integer is required
  • 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-14T04:34:02+00:00Added an answer on May 14, 2026 at 4:34 am

    There are many mistakes you are making here.

    First off, to fix your TypeError, you need to cast your data into int like so:

    ...
    sdy = int(request.POST['start_date_year'])
    #Do the same with the other 5 fields
    

    However, this is a really bad way of doing things. For one, you will have to put try/except blocks around each field to make sure the user entered an integer and not a string.

    Since you are already using Django Forms, why not let it do all the work for you? Here is how you would do this:

    if request.method == 'POST':
        form = ReportFiltersForm(request.POST)
        if form.is_valid():
            start_date = form.cleaned_data['start_date']
            end_date = form.cleaned_data['end_date']
            #Do whatever you need to do with this data now. Since you had
            #defined the fields as DateFields, you will automatically get
            #datetime.date objects.
        else:
            return render_to_response('mytemplate.html', {'form' : form})
    ....
    

    This is a much better way to do things for a couple of reasons. Using this way, you can let Django take care of validating the user input for you. Additionally, it will also cast this data into datetime.date objects. Finally, it will allow you to give better error messages to your user if they entered invalid data.

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

Sidebar

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.