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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:07:27+00:00 2026-06-12T15:07:27+00:00

I start with def start method, it calls go_adder to add the num value

  • 0

I start with def start method, it calls go_adder to add the num value 5 times in the adder.html until num equals 5. After that, the adder method should return ready=1

In views.py

def start(request):
    num=0
    ready_or_not=go_adder(num)
    return HttpResponse("Ready: %s "%str(ready_or_not))

def go_adder(num):
    ready=0
    if num<5:
        return render_to_response('adder.html',{'num':num})
    elif num==5:
        ready=1
        return ready

def check_post(request,num):
    if request.method == 'POST':
        num+=1
        return adder(num)

When I try to run this snippet code, it works until my “num=5”, Then I get that error :

'int' object has no attribute 'status_code' 
Exception Location: C:\Python27\lib\site-packages\django\middleware\common.py in process_response, line 94

and Traceback says:

C:\Python27\lib\site-packages\django\core\handlers\base.py in get_response
                response = middleware_method(request, response) ...
▶ Local vars
C:\Python27\lib\site-packages\django\middleware\common.py in process_response
        if response.status_code == 404: ...
▶ Local vars 

How can I fix that error ? Could you please help me ?

  • 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-12T15:07:28+00:00Added an answer on June 12, 2026 at 3:07 pm

    The django views need to return an HttpResponse object. You are doing that while num < 5, but then you return an int when num == 5:

    def adder(num):
        ready=0
        if num<5:
            num+=1
            # This renders the template and returns and HttpResponse; good
            return render_to_response('adder.html',{'num':num})
        elif num==5:
            ready=1
            # DONT RETURN AN INT HERE. RETURN AN HttpResponse
            return ready
    

    If all you want for when num==5 is to return a plain text response of the number 1, then you can return an HttpResponse and set the content type:

        elif num==5:
            ready=1
            return HttpResponse(str(ready), content_type="text/plain")
    

    Update 1

    Based on our conversation, you have suggested that you want the view to constantly pass along the count value no matter what, and that you are POST-ing the num value in the actual form. If the number is less than 5 it should return one kind of template, otherwise it should return another kind of template.

    You can combine your two different views into one that will handle both the original GET request when the page is first loaded, and the POST request submitted by your form. Just make sure to point your form at that same page.

    def check(request):
        num = 0
    
        if request.method == 'POST':
            num = int(request.POST.get('num'))
    
        return adder(num)
    
    def adder(num):
        if num < 5:
            num += 1
            tpl_name = 'adder.html'
        else:
            tpl_name = 'print.html'
    
        return render_to_response(tpl_name, {'num':num})
    
    • check() is your single view.
    • adder() is the helper function that will add the value, check it, and return an HttpResponse object based on that value. You must always return this from your view to the client.
    • Both templates will be passed the context containing the value of num

    Update 2

    You said that you are actually passing in your num through the url and not through the POST form. Small adjustment to the last example. You don’t even need an adder() anymore. You only need a single view.

    Set your url to have an optional num pattern:

    urls.py

    (r'^checker/(?P<num>\d+)$', 'myapp.views.check')
    

    views.py

    def check(request, num=0):
        num = int(num)
        if num < 5:
            num += 1
            tpl_name = 'adder.html'
        else:
            tpl_name = 'print.html'
    
        return render_to_response(tpl_name, {'num':num})
    

    Your “checker” url now has an optional number. If it is not passed in the url, it will be a value of 0 in the view. If you send it as a POST request, it will add and return a different template.

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

Sidebar

Related Questions

Given the following method: def some_method :value end The following statements work as I
According to the docs, super(cls, obj) returns a proxy object that delegates method calls
I have methods in all of my models that look like this: def formatted_start_date
Please, I need help with my code: def start(): def start_tkinter(): global main,l main.destroy()
Suppose code like this: class Base: def start(self): pass def stop(self) pass class A(Base):
I have next 2 blocks of code: def replace_re(text): start = time.time() new_text =
I have a script that calls the facebook test api to automate test account
I have the following code: def show @game = $site.new_game_of_type(params[:id]) @game.start end def update_game_time
I have a method in a rails helper file like this def table_for(collection, *args)
I have a script called jobrunner.py that calls class methods in main.py. See below...

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.