views.py期待在搜索框輸入的文本要在搜索結果頁
from weatherbot.models import Question
from django.template import RequestContext
from django.shortcuts import render_to_response
def search(request):
query = request.GET.get('q')
if query:
results = query
context = RequestContext(request)
return render_to_response('results.html', {"results": results,}, context_instance=context)
urls.py
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^search/$', views.search, name = 'Ask for Weather Updates'),]
search.html
<form method="get" action="/search/">
Search Notecards:<input type="text" name="q" id="id_q" value="{{ query }}"/>
<input type="submit" value="Search" />
</form>
result.html印刷
{% if results %}
{% for result in results %}
{{ result.xxxx }}
{% endfor %}
{% else %}
<h3 class='error'>Please enter a valid UID</h3>
<form method="get" action="//">
Search Notecards:<input type="text" name="q" id="id_q" value="{{ query }}"/>
<input type="submit" value="Search" />
</form>
{% endif %}
我所試圖做的是在搜索框先輸入一個問題,然後使用Django
請在此處發佈您的代碼,而不是鏈接到粘貼bin,修復縮進,並更詳細地解釋您希望發生的事情以及實際發生的情況。 – Alasdair