English 中文(简体)
• 如何扭转在Django名称上的URL搜索功能
原标题:How to do reverse URL search in Django namespaced reusable application

认为我包括名称可再使用的申请:

urlpatterns = patterns(  ,
    # ella urls
    url( ^ella/ , include( ella.core.urls , namespace="ella")),
)

现在,Ella的申请就是这样:

urlpatterns = patterns(   ,
    url( r ^(?P<category>[a-z0-9-/]+)/$ , category_detail, name="category_detail" ),
    # object detail
    url( r ^(?P<category>[a-z0-9-/]+)/(?P<year>d{4})/(?P<month>d{1,2})/(?P<day>d{1,2})/(?P<content_type>[a-z0-9-]+)/(?P<slug>[a-z0-9-]+)/$ ,
        object_detail, name="object_detail" )
)

现在,电话{% url ella: category_detail category="cat%} 工作罚款。 然而,当目标试图与具体内容建立联系时,它就叫了。

from django.core.urlresolvers import reverse
url = reverse( object_detail , kwargs={ required  :  params })

除非改写成文,否则这行不通。

from django.core.urlresolvers import reverse
url = reverse( ella:object_detail , kwargs={ required  :  params })

因此,如果我正确理解的话, 包括可改用名称的空间,便可打破所发申请中的所有内向反向(>)。

是真的? 我错了什么? 是否有办法?

问题回答

由于你有名称空间的卢旺达组合,你需要提及名称空间:概览-名称模式,以便适当扭转这一格局(特别是从角度看)。

But, if you want to avoid this, you may also pass namespace/appname as current_app parameter. There are multiple ways to specify current_app when you are in template. But if you are in view, you need to hard-code as you did, or pass to current_app parameter

url = reverse( object_detail , 
              kwargs={ foo : bar }, 
              current_app=app_name_or_name_space)

参见:

至少在达詹戈,1.8 你们可以写这样的东西:

url = reverse( %s:object_detail % request.resolver_match.namespace, kwargs={ required : params })

<代码>request.resolver_match.namespace is a string contained the namespace of the presentî.





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签