新的python/Django用户(实际上是SO的新用户):
尝试迁移我的Django项目时,出现错误:
RemovedInDjango110Warning: Support for string view arguments to url() is deprecated
and will be removed in Django 1.10 (got main.views.home). Pass the callable instead.
url(r'^$', 'main.views.home')
Run Code Online (Sandbox Code Playgroud)
显然第二个参数不能再是一个字符串了.我来创建这个代码,因为它是通过pluralsight.com的教程,教导如何使用Django与以前的版本(我目前正在使用1.9).老师指示我们从我们在应用中创建的视图中创建urls.py中的urlpatterns.他告诉我们要创建一个urlpattern,如下所示:
from django.conf.urls import url
from django.contrib import admin
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^$', 'main.views.home')
]
Run Code Online (Sandbox Code Playgroud)
参考
def home(request):
return render(request, "main/home.html",
{'message': 'You\'ve met with a terrible fate, haven\'t you?'}) #this message calls HTML, not shown, not important for question
Run Code Online (Sandbox Code Playgroud)
在我创建的应用程序"main"的views.py中.
如果不推荐使用此方法,如何将视图参数作为字符串传递?如果我只是删除引号,如文档(https://docs.djangoproject.com/en/1.9/topics/http/urls/)中所示,我收到错误:
NameError: name 'main' is not defined
Run Code Online (Sandbox Code Playgroud)
我尝试使用本文档中提供的代码"导入"视图或main: …