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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:14:53+00:00 2026-06-13T21:14:53+00:00

I have a Model class. class Search(forms.Form): query=forms.CharField() And, a view function. def search(request):

  • 0

I have a Model class.

class Search(forms.Form):
    query=forms.CharField()

And, a view function.

def search(request):
  c = {}
  c.update(csrf(request))
  if request.method == 'POST': 
    form = Search(request.POST) 
      if form.is_valid():
        search_query=form.cleaned_data['query']
            return HttpResponse("your query: %s" %search_query  , c) 
      else:
        return HttpResponse(form , c)
  else:
    return render_to_response('polls/search.html', c)

And, here is my search.html:

 <form action="/polls/search" method="post">{% csrf_token %}
  <p><label for="query_label">query:</label>
    <input type="text" name="query_txt" id="query_txt_id" /></p>
  <input type="submit" value="Submit" />
 </form>

After giving some characters as input, it always show me the following as plain text(Not as error).

“A server error occurred. Please contact the administrator.”

  • 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-13T21:14:55+00:00Added an answer on June 13, 2026 at 9:14 pm

    The id of your query field is incorrect. Django expects it to be id_query.

    You don’t need to hardcode your form inputs. If you include {{ form.as_p }} in your template, Django will render the form correctly.

    <form action="/polls/search" method="post">{% csrf_token %}
      {{ form.as_p }}
      <input type="submit" value="Submit" />
    </form>
    

    If you really want to hardcode the form in the template, start with the working html that Django produces, and customize it from there. Note that the forms in your template and the snippet below do not display errors. See the docs on customizing the form template for more details.

    <form action="/polls/search" method="post">{% csrf_token %}
      <p><label for="id_query">Query:</label> <input type="text" name="query" id="id_query" /></p>
      <input type="submit" value="Submit" />
    </form>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model like: CAMPAIGN_TYPES = ( ('email','Email'), ('display','Display'), ('search','Search'), ) class Campaign(models.Model):
I have a model: class Example(models.Model): unique_hash = models.CharField(max_length=32,unique=True) content = models.FileField(upload_to='source',blank=True,verbose_name=HTML Content File)
Assume I have this model : class Task(models.Model): title = models.CharField() Now I would
I have a kase model which I am using a simple search form in.
I have this form: in header of my website: <% form_tag request.path, :method =>
I have a model like this: class Search include Mongoid::Document embeds_many :terms accepts_nested_attributes_for :terms
I have the following model class Command(models.Model): server = models.ForeignKey(Server) user_login = models.CharField(max_length=100) user_run
I have model public class UploadOptionModel { public UploadOptionModel() { OutputFormat = outputFormatList.Select(i =>
I have a model class similar to the following: using System; using System.Collections.Generic; using
I have a model class like this: class Note(models.Model): author = models.ForeignKey(User, related_name='notes') content

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.