不推荐使用对url()的字符串视图参数的支持,并且将在Django 1.10中删除(得到)。传递可调用的

时间:2018-04-09 06:40:22

标签: django

来自django.conf.urls导入网址

urlpatterns =  [
    'chat.views',
    url(r'^$', 'about'),

     url(r'^new/$', 'new_room'),
    url(r'^(?P<label>[\w-]{,50})/$', 'chat_room'),
]

任何人都可以帮助我

2 个答案:

答案 0 :(得分:0)

尝试以下代码

from chat import views
from django.conf.urls import url

urlpatterns =  [
    url(r'^$', views.about, name='about'),
    url(r'^new/$', views.new_room, name='new_room'),
    url(r'^(?P<label>[\w-]{,50})/$', views.chat_room, name='chat_room'),
]

答案 1 :(得分:0)

您不应在视图参数中使用字符串。试试这个:

from chat.views import about, new_room, chat_room
from django.conf.urls import url

urlpatterns =  [
    url(r'^$', about),
    url(r'^new/$', new_room),
    url(r'^(?P<label>[\w-]{,50})/$', chat_room),
]