Saturday, January 29, 2011

query did not work

would like to post one bug, since i was sitting 4h on it

For some reasons query did not work.
In the end appeared that it depends on how urls.py are formulated:

urlpatterns = patterns('',
(r'^searchbooks','Finnish2.Fin.views.searchbooks'), # page
http://127.0.0.1:8000/searchbooks is displayed, query works
(r'^SB','Finnish2.Fin.views.searchbooks'), # page http://127.0.0.1:8000/SB
is displayed, query does not work, already print query statement in
views.searchbooks gives empty string
)

Maybe smbd can comment why this happens.


according oldmanual
http://www.djangobook.com/en/1.0/chapter07/


#################################################### Finnish2/Fin/
templates/trial/searchbooks.hmtl

<form action="/searchbooks" method="GET">
<input type="submit" value="checkdata" name="choice">
<textarea cols="100" rows="10" name="q" value="{{ query.0|escape }}">
< </textarea>
</form>

################################################### Finnish2/Fin/
forms.py

from django import forms
from models import Item

class ContactBooksF(forms.Form):
serial_number = forms.CharField(widget=forms.Textarea())


################################################### Finnish2/Fin/
models.py
from django.db import models

class Item(models.Model):
serial_number = models.CharField(max_length=15)

################################################### Finnish2/Fin/
views.py
from forms import ContactBooksF
from django.shortcuts import render_to_response,

def searchbooks(request):
query = request.GET.get('q', ''); print 'searchbooks query=',
query
if query:
print 'in query'
#see http://www.djangobook.com/en/1.0/chapter07/
return render_to_response("c:/Python27/Scripts/Finnish2/Fin/
templates/trials/searchbooks.html", {"query": query })
})

def contactbooks(request):
form = ContactBooksF()
return render_to_response('c:/Python27/Scripts/Finnish2/Fin/
templates/trial/contactbooks.html', {'form': form})

################################################### Finnish2/
urls.py

from django.conf.urls.defaults import *

urlpatterns = patterns('',
(r'^searchbooks','Finnish2.Fin.views.searchbooks'),
)

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment