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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:33:56+00:00 2026-06-11T09:33:56+00:00

I am trying to understand the following code better. It’s working, but I just

  • 0

I am trying to understand the following code better. It’s working, but I just don’t fully understand several elements (questions below):

from django.shortcuts import render_to_response
from mywiki.wiki.models import Page
from django.http import HttpResponseRedirect
from django import forms
import markdown

class SearchForm(forms.Form):
    text = forms.CharField(label='Enter search term')

def search_page(request):
    if request.method =='POST':
        f = SearchForm(request.POST)
        if not f.is_valid():
            return render_to_response('search.html', {'form':f})
        else:
            pages = Page.objects.filter(name__contains = f.cleaned_data['text'])
            return render_to_response('search.html', {'form':f, 'pages':pages})
    f = SearchForm()
    return render_to_response('search.html', {'form':f})

specialPages = {'SearchPage':search_page}

def view_page(request, page_name):
    if page_name in specialPages:
        return specialPages[page_name](request)
    try:
        page = Page.objects.get(pk=page_name)
    except Page.DoesNotExist:
        return render_to_response('create.html', {'page_name':page_name})

    content = page.content    
    return render_to_response('view.html', {'page_name':page_name, 'content':markdown.markdown(content)})
  1. Why do we need to specify that the request.method has to be POST – wouldn’t clicking an HTML button implicitly signal an intent to change/affect something? Or POST is only appropriate when the action affects the database?

  2. How does the line pages = Page.objects.filter(name__contains = f.cleaned_data['text']) work? It takes the model Page(models.Model), but what do the ‘objects’ and ‘filter’ methods do in this case?

  3. In the view_page, why do we need to add (request) in return specialPages[page_name](request)

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-06-11T09:33:57+00:00Added an answer on June 11, 2026 at 9:33 am
    1. The POST test is used as a differentiator.

      When the view is called with GET, the form is rendered. The form specifies that it needs to be submitted with using POST, so the code assumes that a POST request signals the form is submitted.

    2. The objects attribute triggers the actual database query. By adding the .filter() call you specify a more specific database query, one where the name attribute contains the value of f.cleaned_data['text']. The result is a set of database results that match that query.

    3. the specialPages dictionary values are themselves views, and for these to work, you call them with the request parameter. Just like the view_page view callable itself.

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

Sidebar

Related Questions

I was just trying to understand delegates using the following code. public class delegatesEx
I have the following code, I am trying to understand why all the elements
I am trying to understand the following code: #include<stdio.h> #include<stdlib.h> #include<sys/io.h> #define baseport 0x378
i am trying to understand following fragment of javascript code <!DOCTYPE html> <html> <body>
So I am trying to understand OOP more and use it. The following code
I'm trying to understand why the following code results in the encrypted byte array
I am trying to understand what the following code does: glm::mat4 Projection = glm::perspective(35.0f,
I am new to PHP and trying to better understand the wordpress source code.
I've been trying to read and understand a bit more about better code and
I'm trying to understand the following piece of code: # node list n =

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.