You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Django 1.9无法导入django.urls,更换DRF版本无法使用path对象求助

Got it, let's fix this for Django 1.9! Since Django 1.9 doesn't support path() from django.urls, we need to stick with the older url() function (which uses regex patterns) while keeping your existing structure intact. Here's the adjusted code:

from django.contrib import admin
from django.conf.urls import include, url
from rest_slack.views import DRSEventView, DRSCommandView

# Use url() instead of path() since Django 1.9 doesn't support path
api_patterns = ([
    url(r'^web/$', DRSEventView.as_view()),
    url(r'^events/$', DRSCommandView.as_view()),
], 'api')

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^api/v1/', include(api_patterns)),
]

Key adjustments made:

  • Removed the from django.urls import path import entirely — Django 1.9 doesn't include this module, so it was causing your import error.
  • Replaced each path() call with url() using regex patterns that mirror the exact matching behavior of path():
    • path('web/', ...) translates to url(r'^web/$', ...) — the ^ and $ ensure it's an exact match (just like the default behavior of path() in newer Django versions)
    • Same logic applies to path('events/', ...) → url(r'^events/$', ...)
  • Kept your api_patterns tuple with the namespace ('api') intact — include() works the same way with regex-based URL patterns in Django 1.9, so your namespace setup stays functional.

This setup will work perfectly with Django 1.9 without needing to switch DRF versions, since we're using the routing syntax native to your Django version.

内容的提问来源于stack exchange,提问作者Srikant Singh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.12 04:41:57