如何获取current_app在多部署可重用的Django应用程序中使用反向? [英] How to get current_app for using with reverse in multi-deployable reusable Django application?

查看:154
本文介绍了如何获取current_app在多部署可重用的Django应用程序中使用反向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写可重用的应用程序。而且我想部署它几次。



这是urls.py:

  urlpatterns = patterns('',
(r'^ carphotos /',include('webui.photos.urls',app_name ='car-photos')),
(r' ^ userphotos /',include('webui.photos.urls',app_name ='profile-photos')),)

和照片/ urls.py:

  urlpatterns = patterns('webui.photos.views',
url(r'^ $',album_list,name =album-list)
url(r'^ newalbum / $',album_page,{'create':True},name =album-create ),)

在album_list视图中,我想显示用于创建新相册album_page的网址。 p>

我发现我必须使用参数current_app的反向功能获取正确的URL。



但是如何获得这个CURRENT_APP?
我以为答案是简单的。但是我没有在django文档中找到它。



谢谢,Nick

解决方案>

在探索这个话题几天之后,我发现不止一次挂载django应用程序是不现实的。



有可插拔应用程序模式的实现:
http://github.com/nowells/django-pluggables
对我来说看起来太棘手了。



所以我决定将重复的功能转移到自定义标签,并为我的应用程序的每个用法重复模板。我希望使用自定义标签和扩展功能帮助我遵循DRY原则。


I'm writing reusable app. And I want to deploy it several times.

Here is urls.py:

urlpatterns = patterns('',
(r'^carphotos/', include('webui.photos.urls', app_name='car-photos') ),
(r'^userphotos/', include('webui.photos.urls',  app_name='profile-photos') ),)

and photos/urls.py:

urlpatterns = patterns('webui.photos.views',
url(r'^$', album_list, name="album-list" )
url(r'^newalbum/$', album_page, {'create': True}, name="album-create"),)

On the album_list view I want to show url for creating new album album_page.

I found that I have to use parameter current_app of reverse function to get proper URL.

But how to get this current_app? I thought the answer is something simple. But I can't find it in django documentation.

Thanks, Nick

解决方案

After exploring this topic for several days, I found that it isn't natural to mount django app more than once.

There is implementation of pluggable applications pattern: http://github.com/nowells/django-pluggables. It looks too tricky for me.

So I decided to move repeated functionality to custom tags and duplicate templates for each usage of my app. I hope using custom tags and extend feature help me to follow DRY principle.

这篇关于如何获取current_app在多部署可重用的Django应用程序中使用反向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆