我正在使用django 1.9版本,我想在我的应用程序中实现ajax搜索。在文档中,它表示将URL添加到根URL模式。
url(r'^ajax_search/',include('ajax_search.urls')),`
然后我收到导入错误如下:
File "/usr/local/lib/python2.7/dist-packages/django_ajax_search-1.5.1-py2.7.egg/ajax_search/urls.py", line 1, in <module>
from django.conf.urls.defaults import *
ImportError: No module named defaults
任何人都可以帮我解决这个问题吗?
答案 0 :(得分:3)
django.conf.urls.defaults
has been removed from Django 1.6 onwards。
django-ajax-search
包最后一次更新于2013年。该软件包尚未更新很长时间,并且无法顺利运行Django 1.9
您可以找到另一个包,也可以手动更新它。
答案 1 :(得分:0)
django.conf.urls.defaults
,稍后在Django 1.6中将其删除。阅读this。您正在使用的软件包与urls
不兼容Django 1.9。根据Django 1.9 documentation,您应该将urls.py
定义为
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^articles/2003/$', views.special_case_2003),
url(r'^articles/([0-9]{4})/$', views.year_archive),
url(r'^articles/([0-9]{4})/([0-9]{2})/$', views.month_archive),
url(r'^articles/([0-9]{4})/([0-9]{2})/([0-9]+)/$', views.article_detail),
]
<强>更新强>
您可以修改urls.py
,如下所示:
from django.conf.urls import url, include
from ajax_search import views as as_views
ajax_search_urlpatterns = [
url(r'^xhr_search$','as_views.xhr_search'),
url(r'^search/', 'as_views.search'),
]
urlpatterns = [
url(r'^ajax_search/',include(ajax_search_urlpatterns)),
]