我对编码很陌生,而且我在过去的5个小时里一直试图建立一个网站,但它立刻给了我一个错误。我一直在寻找一个解决方案,但还没来一个。
这是错误代码:
C:\Projects\bgcenv\myproject\urls.py:26: RemovedInDjango110Warning: Support for
string view arguments to url() is deprecated and will be removed in Django 1.10
(got myproject.views.index). Pass the callable instead.
url(r'^$', 'myproject.views.index'),
这是我的url.py:
from django.contrib import admin
admin.autodiscover()
try:
from django.conf.urls import url
except ImportError: # django < 1.4
from django.conf.urls.defaults import url
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^$', 'myproject.views.index'),
]
答案 0 :(得分:5)
这看起来像是一个警告,而不是一个错误,但它所说的是url函数(来自django.conf.urls)期望你传递一个函数(或另一个可调用的)而不是一个字符串。您需要从myproject.views导入索引并传递:
from django.contrib import admin
admin.autodiscover()
try:
from django.conf.urls import url
except ImportError: # django < 1.4
from django.conf.urls.defaults import url
from myproject import views
urlpatterns = [
url(r'^admin/', admin.site.urls),
#url(r'^$', 'myproject.views.index'),
url(r'^$', views.index),
# Importing the views module you can
# now conveniently register other views:
# url('r^/blah/', views.blah),
]