POOJA GUPTA
POOJA GUPTA

Reputation: 2355

how to design a page in django cms

I want to design a page in django that has a search bar in which user enters a keyword to search it in the 10 xml documents . I have designed the python code for searching the words using xml parsing. I also have developed an app called "search" in django but that app has to have this page that I want to design. Right now, my app is taking input from the terminal but I want that the word should be entered through this web page that I will design. How can I do that?

This is my code that will sit at back end:

#!/usr/bin/python

import sys 
sys.path.insert(0,'/home/pooja/Desktop/mysite')

#to tell django which settings module to use 
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'

from search.models import Keywords 

from skey import find_root_tags, count, sorting_list

str1 = raw_input("enter the word to be searched\n")  # taking input from user on terminal but I want it to be taken through that page
list = []
fo = open("xml.txt","r")

for i in range(count.__len__()):

    file = fo.readline()
    file = file.rstrip('\n')
    find_root_tags(file,str1,i) 

    list.append((file,count[i]))

sorting_list(list)

for name, count in list:
    s = Keywords(file_name=name,frequency_count=count)
    s.save()

fo.close()

Here django_project = mysite #my project's name and app = search #my app's name

Please help.

Upvotes: 0

Views: 224

Answers (3)

Ghopper21
Ghopper21

Reputation: 10477

You are currently using Django's database models (i.e. Keywoards). To add a webpage input, the typical way is to use:

  1. a Django template -- i.e. HTML annotated with Django-specific template markup code -- that includes an HTML form with the search field and a submit button.

  2. a Django view that provides the backend logic for the template above -- i.e. a Python function that (1) causes the empty search form (from the template above) to be shown to the user at first and (2) receives the user's search input (via a Django "request" triggered when the user clicks submit), causes it to be processed (along the lines in your code above), and presumably says back "Thanks, search processed" or whatever (via a "response" that Django handles for you).

  3. a Django URLconf configuration line (in your project's settings.py module) that tells Django to route whatever URL you want to use for your search interface to the view above.

If that stuff is new to you, I'd suggest spending some time with the online Django Book, especially the chapters on Views and URLconfs, Templates, and Forms. Note the chapter on Forms actually uses a simple search example similar to what you are trying to do, which hopefully should be especially helpful in showing how all the pieces fit together.

Upvotes: 1

Mohammad Efazati
Mohammad Efazati

Reputation: 4920

create view in search app with form and recive search key and ...

see these pages

Upvotes: 2

Aidas Bendoraitis
Aidas Bendoraitis

Reputation: 4003

Read how to create forms in Django documentation: https://docs.djangoproject.com/en/1.4/topics/forms/

Upvotes: 0

Related Questions