django url标记性能

django url标记性能,django,performance,Django,Performance,我试图按照指示将django投票集成到我的项目中 在我的URL.py中,我做了如下操作: url(r'^sections/(?P<object_id>\d+)/(?P<direction>up|down|clear)vote/?$', vote_on_object, dict( model=Section, template_object_name='section', template_name='

我试图按照指示将django投票集成到我的项目中

在我的URL.py中,我做了如下操作:

    url(r'^sections/(?P<object_id>\d+)/(?P<direction>up|down|clear)vote/?$',
    vote_on_object,
    dict(
        model=Section,
        template_object_name='section',
        template_name='script/section_confirm_vote.html',
        allow_xmlhttprequest=True
        ),
    name="section_vote",
<form class="sectionvote" id="sectionup{{ section.id }}"{% if vote and vote.is_upvote %} action="sections/{{section.id}}/clearvote/"{% else %} action="sections/{{section.id}}/clearvote/"{% endif %} method="POST">
url(r'^sections/(?P\d+)/(?Pup | down | clear)投票/?$,
就你的目标投票,
口述(
模型=截面,
模板\u对象\u名称='section',
模板\u name='script/section\u confirm\u vote.html',
允许\u xmlhttprequest=True
),
name=“部分投票”,
然后,在我的模板中:

    {% vote_by_user user on section as vote %}
{% score_for_object section as score %}

<form class="sectionvote" id="sectionup{{ section.id }}"{% if vote and vote.is_upvote %} action="{% url section_vote object_id=section.id, direction="clear" %}"{% else %} action="{% url section_vote object_id=section.id, direction="up" %}"{% endif %} method="POST">
<input type="image" id="sectionuparrow{{ section.id }}" src="{{ MEDIA_URL }}/aup{% if vote and vote.is_upvote %}mod{% else %}grey{% endif %}.png"></form>

{{ score.score|default:0 }}

<form class="sectionvote" id="sectiondown{{ section.id }}"{% if vote and vote.is_downvote %} action="{% url section_vote object_id=section.id, direction="clear" %}"{% else %} action="{% url section_vote object_id=section.id, direction="down" %}"{% endif %} method="POST"> 
<input type="image" id="sectiondownarrow{{ section.id }}" src="{{ MEDIA_URL }}/adown{% if vote and vote.is_downvote %}mod{% else %}grey{% endif %}.png"></form>
{u用户对节的%vote\u作为vote%}
{u对象部分的%score\u作为分数%}
{{score.score}默认值:0}
加载页面需要1.3秒以上的时间,但通过如下硬编码:

    url(r'^sections/(?P<object_id>\d+)/(?P<direction>up|down|clear)vote/?$',
    vote_on_object,
    dict(
        model=Section,
        template_object_name='section',
        template_name='script/section_confirm_vote.html',
        allow_xmlhttprequest=True
        ),
    name="section_vote",
<form class="sectionvote" id="sectionup{{ section.id }}"{% if vote and vote.is_upvote %} action="sections/{{section.id}}/clearvote/"{% else %} action="sections/{{section.id}}/clearvote/"{% endif %} method="POST">


我得到了50毫秒。只要避免url标签解析的东西,我的性能提高了20多倍。
有什么我做错了吗?如果没有,那么这里的最佳实践是什么,我们应该用
正确的方法还是快速的方法做事情?

如果您使用的是开发版本,最近出现了一个回归,它大大增加了反向查找URL所需的时间-请参阅。它计划在最终版本之前修复1.2的发行版。

只需添加:该问题现在已经修复,因此如果您升级,它应该会更快。刚刚完成,相同的视图,32ms。1.2rc的错误减少了一个:)再次感谢Daniel。