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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:49:55+00:00 2026-05-31T08:49:55+00:00

Newbie question: I need to accept a parameter in a form from a method

  • 0

Newbie question:
I need to accept a parameter in a form from a method in views.py but it gave me troubles. In the view I created a method with following snippet:

def scan_page(request):
    myClient = request.user.get_profile().client
    form = WirelessScanForm(client = myClient)   # pass parameter to the form

and in the forms.py I defined the following form:

class WirelessScanForm(forms.ModelForm):
    time = forms.DateTimeField(label="Schedule Time", widget=AdminSplitDateTime())

    def __init__(self,*args,**kwargs):
        myClient = kwargs.pop("client")     # client is the parameter passed from views.py
        super(WirelessScanForm, self).__init__(*args,**kwargs)
        prob = forms.ChoiceField(label="Sniffer", choices=[ x.sniffer.plug_ip for x in Sniffer.objects.filter(client = myClient) ])

But django keeps giving me error saying: TemplateSyntaxError: Caught NameError while rendering: name 'myClient' is not defined(This error happens in the query)

I’m afraid it would be something stupid missing here, but I cannot really figure out why. Please help, 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-31T08:49:57+00:00Added an answer on May 31, 2026 at 8:49 am

    Assuming I’ve corrected your formatting properly, you have an indentation issue: prob is outside __init__, so doesn’t have access to the local myClient variable.

    However if you bring it inside the method, it still won’t work, as there are two other issues: first, simply assigning a field to a variable won’t set it on the form; and second, the choices attribute needs a list of 2-tuples, not just a flat list. What you need is this:

    def __init__(self,*args,**kwargs):
        myClient = kwargs.pop("client")     # client is the parameter passed from views.py
        super(WirelessScanForm, self).__init__(*args,**kwargs)
        self.fields['prob'] = forms.ChoiceField(label="Sniffer", choices=[(x.plug_ip, x.MY_DESCRIPTIVE_FIELD) for x in Sniffer.objects.filter(client = myClient)])
    

    Obviously replace MY_DESCRIPTIVE_FIELD with the actual field you want displayed in the choices.

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

Sidebar

Related Questions

Sorry fot his newbie question. But I really need a start on this one.
A python newbie question: I need to do the following try: do-something() except error1:
I'm sorry for this newbie question, but I need a quick answer to tell
Sorry for this newbie question, but I can't find on google what I need
this might be quite a newbie question, but i need to process a certain
Newbie question: I just installed VisualSVN Server and created a repository. I noticed that
Total newbie question but this is driving me mad! I'm trying this: myInt =
Newbie question. After I have written the Android App (easy part) I need to
I'm going to ask a newbie question here. I need to use a control
I'm starting with developing, sorry about this newbie question. I need to create a

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.