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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:18:43+00:00 2026-05-14T15:18:43+00:00

i have a function that give me the result that im expecting in console

  • 0

i have a function that give me the result that im expecting in console mode, but if i try to use the function with Django, the page never load and just have a loop calculating and never end.

Any idea ?
*sorry with my english

Console function (WORK GREAT):

def sum_digitos(n):
    sum = 0;
    while n != 0:
        sum += n % 10
        n /= 10

        if sum > 9:
            x = str(sum)
            y =list(x)
            sum = int(y[0]) + int(y[1])

    return sum

print sum_digitos(2461978)

Django views:

def Calcular(request):
        if request.method == 'POST':
            form = NumerologiaForm(request.POST)
            if form.is_valid():
                sum = 0;

                ano = str(request.POST['fecha_year'])
                mes = str(request.POST['fecha_month'])
                dia = str(request.POST['fecha_day'])

                data = dia + mes + ano
                fecha = int(data)

                while fecha != 0:
                    f = fecha
                    sum += f % 10
                    f /= 10

                    if sum > 9:
                        x = str(sum)
                        y =list(x)
                        sum = int(y[0]) + int(y[1])

                resultado = get_object_or_404(Numero,numero = sum)
            return HttpResponseRedirect(resultado.get_absolute_url())
        else:
            form = NumerologiaForm()
        return render_to_response('numerologiaForm.html',{'form':form})
  • 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-14T15:18:44+00:00Added an answer on May 14, 2026 at 3:18 pm

    Sanjay’s answer is the correct one, and I recommend it. I just wanted to ask why you didn’t just do:

    from numerology import sum_digitos
    
    def Calcular(request):
        # In your code, you return HttpResponseRedirect using a nonexistent 
        # "resultado" variable if the form is not valid. This will raise an 
        # exception. I think you meant to indent "return Http..." one step more.
    
        if request.method == 'POST':
            form = NumerologiaForm(request.POST)
        else:
            form = NumerologiaForm()
    
        # "or..." part of next line not needed if form.is_valid() returns 
        # False for a blank form.
        if not form.is_valid() or form == NumerologiaForm():
            return render_to_response('numerologiaForm.html', {'form': form})
    
        ano = str(request.POST['fecha_year'])
        mes = str(request.POST['fecha_month'])
        dia = str(request.POST['fecha_day'])
        resultado = get_object_or_404(Numero, 
            numero=sum_digitos(int(dia + mes + ano)))
    
        return HttpResponseRedirect(resultado.get_absolute_url())
    

    You had a working function in Python already… why not just import it and use it?

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

Sidebar

Related Questions

I have a small JavaScript function that (among other things) retrieves the ID of
I have the current week as an integer (43 as of now). I need
I'm trying to find a better approach that my current one to manage the
Some days ago I was searching on the net and I found an interesting
I'm pretty new to Javascript, as my SO profile will attest. I've just been
I've got a situation which I want to fetch data from a database, and
When I attempt this query: $query = SELECT * FROM user_objects WHERE object_type =
How is STL vector usually implemented? It has a raw storage of char[] which
I am trying to understand tail-recursion in Haskell. I think I understand what it
I'm converting an algorithm from C# to C++. A small part of the algorithm

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.