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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:58:42+00:00 2026-06-06T22:58:42+00:00

I have the given view and template code, when i try to run this

  • 0

I have the given view and template code, when i try to run this code i get the following errors.when i searched about this type of error,i found that it happens when a variable and function is given the same name,but could’t correct it in my code.

 Environment:

 Request Method: GET
 Request URL: http://127.0.0.1:8000/budget/show/
 Django Version: 1.2.5
 Python Version: 2.7.1
 Installed Applications:
 ['django.contrib.admin',
  'django.contrib.auth',
  'django.contrib.contenttypes',
  'django.contrib.sessions',
  'django.contrib.sites',
  'django.contrib.messages',
  'mysite.bug']
  Installed Middleware:
  ('django.middleware.common.CommonMiddleware',
  'django.contrib.sessions.middleware.SessionMiddleware',
  'django.middleware.csrf.CsrfViewMiddleware',
  'django.contrib.auth.middleware.AuthenticationMiddleware',
   'django.contrib.messages.middleware.MessageMiddleware')


 Traceback:
    File "/usr/lib/pymodules/python2.7/django/core/handlers/base.py" in get_response 100.                     response = callback(request, *callback_args,   **callback_kwargs)
    File "/home/nimesh/budman/mysite/../mysite/bug/views.py" in shown 252.             
    return render_to_response('budgetfinalform3.html', {'account_number': c,'period':d,'month':e,'year':f,'formsetlist': formset,'child':child},context_instance=RequestContext(request))

     Exception Type: UnboundLocalError at /budget/show/
     Exception Value: local variable 'formset' referenced before assignment                 

plz help me to remove this error.

def show (request):
b = request.session["s1"]
c = request.session["s2"]
d = request.session["s3"]
a = account_period.objects.filter(year=d).values('id')
e = account_period.objects.filter(year=d).values('month')
f = account_period.objects.filter(id = a).values('year')

try:
        child = account_tab.objects.filter(parent_account_number=c).values('account_number')
        noofchild = account_tab.objects.filter(parent_account_number=c).count()
except account_tab.DoesNotExist:
        noofchild = 0
if noofchild != 0 :   
       formsetlist = []


       for i in range(0, noofchild):
        formsetlist.append(formset_factory(bu, extra=b))
    if request.method == 'POST':

     formsetlist2.append(formsetlist[i](request.POST))

     if formsetlist2[i].is_valid():
       j=0
       for form in formsetlist2[i].forms:
         z = account_tab.objects.get(account_number = child[i:(i+1)])
         x = form.cleaned_data['value']
         y = account_period.objects.get(id=a[j:(j+1)])
         try:
                uip = budget.objects.get(account_no = child[i:(i+1)],account_period = a[j:(j+1)])
                if uip.budget_amount != x:

                  uip.budget_amount = x
                  uip.save()

         except budget.DoesNotExist:

                w = budget(account_no = z, account_period = y, budget_amount = x, created_by_login = 'me')
                w.save()
         j=j+1
       pass
       return HttpResponse('thanks')


    else:
             return render_to_response('budgetfinalform3.html', {'account_number': c,'period':d,'month':e,'year':f,'formsetlist': formset,'child':child},context_instance=RequestContext(request))
     #return HttpResponse(mes)

Template code is

    <html>
    <head>
    <title>BUDGET</title>
    </head>
    <body>
    <h1>BUDGET MANAGEMENTS</h1>
    <h2>Your Account Number is : {{ account_number }}.</h2> <h2>You Chose {{ period }} {{month}} as period</h2>   

    {% if form.errors %}
    <p style="color: red;">
        Please correct the error{{ form.errors|pluralize }} below.
    </p>
    {% endif %}


    <form action="." method="post">{% csrf_token %}
    {% for formset in formsetlist %}
    {{ formset.management_form }}
    {{child}}

    <table>
    {% for form in formset.forms %}

    {% if forloop.counter == 0  %}
     {{child.1}}
    {% endif%}
    {{ form }}
    {% endfor %}
    </table>   
    {% endfor %}
    <input type="submit" value="Submit">
    </form>
    </body>
    </html>
  • 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-06T22:58:43+00:00Added an answer on June 6, 2026 at 10:58 pm
    return render_to_response('budgetfinalform3.html', {'account_number': c,'period':d,'month':e,'year':f,'formsetlist': formset,'child':child},context_instance=RequestContext(request))
    

    Uses formset but it looks/sounds like you meant formsetlist:

    return render_to_response('budgetfinalform3.html', {'account_number': c,'period':d,'month':e,'year':f,'formsetlist': formsetlist,'child':child},context_instance=RequestContext(request))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given that I have this code: Ember.App.View = Ember.View.extend({ templateName: templateA }); Ember.App.View =
In my WPF application I have a View that is given a ViewModel, and
I have a Django project. Given a url, how can I know which view
I have the following case: Edited: removed link In IE7 gives me different view
I have Xcode 4.2, and I selected the project template Master Detail view without
In my application i have the following classic template on 3 columns ********************************************************* *
I have this code(which doesn't give me expected result) #subject_content.html {% block main-menu %}
I have the following field in my model: public Decimal AnnualSalary { get; set;
I have 5 check box on my page and a Grid view with Template
I have been given the task to recreate the following menu: I am just

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.