问一下django 的 时间/ID 这样传递两个参数的正则url 怎么写? 详情..

cndeer cndeer 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
最终目标是想要写这样的网址:aaa.com/201407/89978.html

现在 
url(r'^(?P<pk>\d+).html$', job_arc.as_view(), name='job_arc'), 


这样在写网址的时候
<a href="{% url 'job_arc'  list.id %}" target="_blank">{{ list.title }}</a> 


传递 一个变量 id 也就是上面的89978

这样出来的是:aaa.com/89978.html

现在要是写成这样:

url(r'^job/(?P<year>\d{4})(?P<month>\d{2})/(?P<pk>\d+).html$', job_arc.as_view(), name='job_arc'),


这样的话怎么传递这个日期时间pubdate 给urls里呢?

数据库有字段 pubdate 这个时间字段  不知道上面的正则写的对不? 

反正要实现aaa.com/201407/89978.html 这样的时间/ID做为网址的功能.要怎么弄好?



ps: views.py 里这样写的:


class job_arc(DetailView):
model = dede_archives
template_name = 'job/job_arc.html'
def get_object(self):
object1 = super(job_arc, self).get_object()
object1.click += 1
object1.save()
return object1

...全文

相关推荐

评论 1
收藏 已收藏
分享
返回顶部
cndeer
脚本语言 37,737 成员 34,208 内容