【发布时间】:2014-11-22 19:08:21
【问题描述】:
在我开始之前,请原谅我的英语,HTML 新手,这是我正在创建的第一个 django 应用程序。
假设我想根据表单中的输入查看静态图像以进行测试,所以如果我输入表单 goat.jpg 它将显示 goat.jpg
这是我的html
<!DOCTYPE html>
{% load static %}
<html>
<head>
<title>test</title>
</head>
<body>
<center><img src="{% static "{{staticpath}}" %}" alt="gif" align="middle"/></center>
{{boldmessage}}
这是我的看法
from django.shortcuts import render
from django.http import HttpResponse
from django.template import RequestContext
from django.shortcuts import render_to_response
def generate(request):
context = RequestContext(request)
if request.GET:
path = request.GET.get('path','')
context_dict = {'staticpath':path}
return render_to_response("generated/generated.html", context_dict, context)
path 已经是一个字符串,但是如果我删除 staticpath 双引号 django 会引发异常。那么如何将路径的字符串准确地放入 html 图像源中,以便正确显示静态图像呢?谢谢!
【问题讨论】: