【问题标题】:Django, Truncated incorrect DOUBLE value:Django,截断不正确的 DOUBLE 值:
【发布时间】:2010-01-04 00:33:27
【问题描述】:

我有这个错误:

Truncated incorrect DOUBLE value: 'asinox'

此错误来自我的 SEO 网址:

http://127.0.0.1:8000/user/asinox/2010/dec/30/1/este-pantalon-lo-compre-en-plaza-lama-una-aperidad/

“asinox”是用户名(usuario),路由URL是这样的:

(r'^(?P<usuario>[-\w]+)/(?P<year>\d{4})/(?P<month>\w{3})/(?P<day>\d{2})/(?P<pk>\d+)/(?P<slug>[-\w]+)/$', shared),

我不知道为什么会出错,但这是我的看法:

def shared(request,usuario,year, month,day, pk, slug):
    import datetime, time
    date_stamp= time.strptime(year+month+day, "%Y%b%d")
    pub_date = datetime.date(*date_stamp[:3])
    shared = get_object_or_404(Show,usuario=usuario,
                               pub_date__year=pub_date.year,
                               pub_date__month=pub_date.month,
                               pub_date__day=pub_date.day,
                               pk=pk,
                               slug=slug)
    return render_to_response('site/account/shared.html',
                              {'shared': shared},
                              context_instance=RequestContext(request))

请问有什么想法吗?

谢谢,对不起我的英语。

【问题讨论】:

  • 我认为问题在于 urls.py 中的 [-\w]+,但我不确定该正则表达式是否就是您想要的。
  • 我解决的问题是我像“string”一样调用用户......并且用户(id)是一个int。

标签: django django-urls


【解决方案1】:

那个正则表达式根本不匹配 URL。您的 URL 以文字字符串“用户”开头,该字符串不在正则表达式中;并且正则表达式还需要一个整数 PK 值,而 URL 没有。

【讨论】:

  • 我的猜测是来自另一个 url.py 的某种包含,而 1 是 pk。
  • 这个答案看起来不错。它将文字“用户”作为您的用户名,然后将“asinox”传递给......实际上 asinox 不应该传递到年份,因为年份只接受数字。这看起来根本不应该匹配。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-07
  • 1970-01-01
  • 2018-06-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多