在过去的几个小时里,我一直在争论这个问题.我无法显示{{MEDIA_URL}}
在settings.py中
..
MEDIA_URL = 'http://10.10.0.106/ame/'
..
TEMPLATE_CONTEXT_PROCESSORS = (
"django.contrib.auth.context_processors.auth",
"django.core.context_processors.media",
)
..
Run Code Online (Sandbox Code Playgroud)
在我看来,我有
from django.shortcuts import render_to_response, get_object_or_404
from ame.Question.models import Question
def latest(request):
Question_latest_ten = Question.objects.all().order_by('pub_date')[:10]
p = get_object_or_404(Question_latest_ten)
return render_to_response('Question/latest.html', {'latest': p})
Run Code Online (Sandbox Code Playgroud)
然后我有一个base.html和问题/ latest.html
{% extends 'base.html' %}
<img class="hl" src="{{ MEDIA_URL }}/images/avatar.jpg" /></a>
Run Code Online (Sandbox Code Playgroud)
但MEDIA_URL显示空白,我认为这是它的假设,但也许我错了.
更新 最新版本修复了这些问题.
这更像是一种偏好,但我想知道人们认为什么是最佳选择.我有一个问题,答案和点(因为我需要跟踪哪个用户指出了这一点)
表转储
Question:
id
title
Answer:
id
question_id
user_id
response
Point_Answer:
id
answer_id
user_id
points
Run Code Online (Sandbox Code Playgroud)
因此,在此布局中获取Top Answer将需要复杂的连接序列.
SELECT t2.id, t2.user_id, t2.response, MAX(points)
FROM Question as t1,
(SELECT qa.*, SUM(pa.points) as points
FROM answer as qa, Point_Answer as pa
WHERE qa.id = pa.answer_id
GROUP BY qa.id) as t2
WHERE t1.id = %s AND t1.id = t2.question_id
Run Code Online (Sandbox Code Playgroud)
如果我这样改变它:
Question:
id
title
Answer:
id
question_id
user_id
response
points
Point_Answer:
id
answer_id
user_id
points
Run Code Online (Sandbox Code Playgroud)
查询的负担会减轻
SELECT A.id, A.user_id, A.response, MAX(points)
FROM Question as Q, …Run Code Online (Sandbox Code Playgroud)