我是 django 的新手,我正在构建一个测试 FileField 的站点
现在我可以上传文件、搜索和获取文件的 url,但是当我点击网络链接时,它返回“找不到页面 (404)”
我的代码是:
在views.py中:
from django.shortcuts import render, get_object_or_404
from granada.models import Hojas
def index(request):
return render(request, 'index.html')
def search_form(request):
return render(request, 'search_form.html')
def search(request):
errors = []
if 'field1' in request.GET:
field1 = request.GET['field1']
field2 = request.GET['field2']
if not (field1 or field2):
errors.append('Enter a search term.')
else:
results = Hojas.objects.filter(
mes__icontains=field1
).filter(
agno__icontains=field2
)
query = "%s, %s" % (field1, field2)
return render(request, 'search_results.html',
{'results': results, 'query': query})
return render(request, 'search_form.html',
{'errors': errors})
和我的 search_results.html
<p>Buscó la hoja del mes y año: <strong>{{ query }}</strong></p>
{%for result in results%}
<div class="post">
<ul>
<h3>
<a href="{{ result.Granada.url }}">
{{result}}
</a>
</h3>
</ul>
{%endfor %}
我的网址.py
from django.conf.urls import patterns, include, url
from django.contrib import admin
from granada import views
admin.autodiscover()
urlpatterns = patterns('',
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
url(r'^admin/', include(admin.site.urls)),
(r'^search-form/$', views.search_form),
(r'^search/$', views.search),
最后是媒体设置
MEDIA_URL = 'http://localhost:8000/'
STATIC_ROOT = '/home/zanklord/Dropbox/django/taqwim/