English 中文(简体)
利用Django模板,但没有返回吉大港山区
原标题:String from Django template, but without returning a HTTPResponse

我有一个问询组,我喜欢用它的目标来填满一个模板。 我的看法已经结束。

return render_to_response( entry.json , { entry_list :r}, mimetype="application/json; charset=utf-8")

但 我愿照相,在不必返回吉大港定居区的情况下,照此办理。 在假体编码中,这可能是:

render( entry.json , { entry_list :r}) #returns a string with the template entry.json

这是可能的吗? 如果是,如何?

最佳回答

Django为此提供了一座建筑。

https://docs.djangoproject.com/en/dev/ref/templates/api/#the-render-to-string-shortcut

我不理解你试图完成的工作,但你只能作为你的吉斯人回来。 您可以把物体编成ja子,并在不使用任何模板的情况下将其退回。

问题回答

@HankGay所说的话是正确的,尽管你有时可能希望得到模板的答复,以收回HttpResponse,尽管你正在正确使用Django。

http://docs.djangoproject.com/en/dev/ref/templates/api/#rendering-a-context”rel=“noreferer” 提交背景:

>>> from django.template import Context, Template
>>> t = Template("My name is {{ my_name }}.")

>>> c = Context({"my_name": "Adrian"})
>>> t.render(c)
"My name is Adrian."

>>> c = Context({"my_name": "Dolores"})
>>> t.render(c)
"My name is Dolores."

你们会记得什么?

如果你不处理吉卜赛人的申请,那么诚实地利用詹戈就没有意义。 参看Jinja 2 ,用于一个简单的模版发动机,该发动机的批量为通用的W/Djangos,,用于一个等于或大于Django的OM。





相关问题
Check session from a view in CodeIgniter

What is the best way to check session from a view in CodeIgniter, it shows no way in their user guide, otherwise I will have to make two views on everything, which is kinda weird...still a newbie to ...

How to create a submit button template in Oracle APEX?

I m trying to create a template for a button in Oracle APEX but I don t seem to have access to the appropriate substitution strings to make it work. For non-templated buttons APEX seems to insert a ...

list of controls with templates in silverlight

Does anyone know where to find a list of controls that you can set the template on in Silverlight? I ve wasted several hours now trying to create control templates only to find that the control doesn ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Load ruby on rails template from database

I wonder if there is a way for me to store ruby on rails view files into database store and have that fetched directly from there. The reason is I want to create a CMS with all the user data stored in ...

Templated HTML Editor

I m looking for a HTML editor that kinda supports templated editing or live snippets or something like that. Background: I m working on a website for a friend. As there are no specifications what the ...

Dreamweaver changing path to site s reference instead of local

I have noticed recently, when I apply a template to a new HTML website, all the relative paths are pointed to my local files, example: file:///C|/webstuff/files but I cannot set them to relative paths ...

WPF ListView : Header styling

I want to have a ListView with columns and a particular style: The background for ALL column headers should be transparent except when the mouse is over in one of them. When this happends, the ...

热门标签