在url conf中包含/传递slug和pk(或任何其他变量)

时间:2016-10-12 08:26:38

标签: django django-templates

目前我的配置看起来像这样:

urls.py:

url(r'^(?P<slug>[-_~\w]+)/$', SomeDetailView.as_view(), name='detail'),

views.py很简单:

class GetDetailView(SomeDetailViewMixin, DetailView):
    model = Dummy
    template_name = "detail.html"

和html是这样的:

<h2><a href="{% url 'detail' i.slug %}" rel="nofollow"></a>Text</h2>

..一切都很好。但是,我现在正在寻找的是通过html将另一个变量(例如pk - 说var2)传递给url conf。所以,像:

html(这是一个ListView):

<h2><a href="{% url 'detail' i.slug i.var2 %}" rel="nofollow"></a></h2>

和urls.py类似:

url(r'^(?P<slug>[-_~\w]+)/$', SomeDetailView.as_view(), kwargs={'var2': var2}, name='detail'),

是否可以沿着这些方向发展?我不想要的是在网址中包含var2(因为var2是ugly)...

我记得一年前在这些方面做过一些事情,但我的记忆让我再次失望......

非常感谢任何帮助...

1 个答案:

答案 0 :(得分:0)

这应该是您可以从 private findLocalChatsWithLastMessageForChat(): Promise<Mongo.Collection<Chat>> { let promise: Promise<Mongo.Collection<Chat>> = new Promise<Mongo.Collection<Chat>>(resolve => { let localChatCollection: Mongo.Collection<Chat> = new Mongo.Collection<Chat>(null); // ----------------- // ARRAY OF PROMISES let promises: Array<Promise> = []; // ----------------- for (let i: number = 0; i < this.chatsStorageService.chats.length; i++) { let chat: Chat = this.chatsStorageService.chats[i]; let findLastMessageForChatPromise: Promise<Message> = this.chatsStorageService.findLastMessageForChat(chat); // ----------------- // PUSH ALL YOUR PROMISES IN promises ARRAY promises.push(findLastMessageForChatPromise); // ----------------- // Binding 'chat' in order to don't loose it. findLastMessageForChatPromise.then(function (_chat, data) { let message: Message = data; _chat.lastMessage = message; _chat.lastMessageCreatedAt = message.createdAt; localChatCollection.insert(_chat); }.bind(null, chat)); } // ----------------- // WAIT FOR ALL PROMISES BEFORE RESOLVING Promise.all(promises).then(function() {resolve(localChatCollection);}); // ----------------- }); return promise; } 本身确定的信息。所以你根本不需要它在url模板标签中。所以,因为你已经通过

i从对象访问它
DetailView