变量和 Django URLConf

发布于 2024-10-08 05:02:53 字数 325 浏览 10 评论 0原文

我无法从 URL 中提取字符串。这就是我所得到的..它不断出现 404ing。

urls.py:views.py

urlpatterns = patterns('',
    (r'^user/(?P<username>\w{0,50})/$', profile,),
)

  def profile(request, username):
            ... 
      return ...

看到任何明显的东西了吗?需要更多吗?任何帮助表示赞赏。

I'm having trouble extracting a string from my URL. Here's what I've got.. it keeps 404ing.

urls.py:

urlpatterns = patterns('',
    (r'^user/(?P<username>\w{0,50})/

views.py:

  def profile(request, username):
            ... 
      return ...

See anything obvious? Need more? Any help is appreciated.

, profile,), )

views.py:

See anything obvious? Need more? Any help is appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

水晶透心 2024-10-15 05:02:53

我通常在 url 模式末尾添加 /?$

这是一个常见的错误,有些浏览器添加或不添加尾随“/”。

I usually a /?$ at end of url pattern.

It is a common mistake and some browser add or not a trailing '/'.

深陷 2024-10-15 05:02:53

您是否已在 URL 文件顶部导入了视图模块?

from views import profile

urlpatterns = patterns('',
    (r'^user/(?P<username>\w{0,50})/

您的设置文件中是否有 DEBUG = True ?这将有助于通过您应该向我们展示的堆栈跟踪来查找错误。

, profile), # also removed trailing comma after profile ) # alternative urlpatterns = patterns('', (r'^user/(?P<username>\w{0,50})/

您的设置文件中是否有 DEBUG = True ?这将有助于通过您应该向我们展示的堆栈跟踪来查找错误。

, 'views.profile'), )

您的设置文件中是否有 DEBUG = True ?这将有助于通过您应该向我们展示的堆栈跟踪来查找错误。

Have you imported your views module at the top of your URL file?

from views import profile

urlpatterns = patterns('',
    (r'^user/(?P<username>\w{0,50})/

Have you got DEBUG = True in your settings file? That'll help find errors with a stacktrace that you should show us.

, profile), # also removed trailing comma after profile ) # alternative urlpatterns = patterns('', (r'^user/(?P<username>\w{0,50})/

Have you got DEBUG = True in your settings file? That'll help find errors with a stacktrace that you should show us.

, 'views.profile'), )

Have you got DEBUG = True in your settings file? That'll help find errors with a stacktrace that you should show us.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文