菜鸟问个初学 Django 的问题 RemovedInDjango110Warning

2015-12-03 13:49:31 +08:00
 Banio
刚学 Django 安装 http://www.cnblogs.com/vamei/p/3531740.html 这篇文章里操作的
我执行完$python manage.py migrate 之后 终端这样显示

`vagrant@Vbox-5-0-6:~/mysite$ python manage.py migrate
/usr/lib/python2.7/dist-packages/pkg_resources.py:1031: UserWarning: /home/vagrant/.python-eggs is writable by group/others and vulnerable to attack when used with get_resource_filename. Consider a more secure location (set with .set_extraction_path or the PYTHON_EGG_CACHE environment variable).
warnings.warn(msg, UserWarning)`

`/home/vagrant/mysite/mysite/urls.py:36: RemovedInDjango110Warning: Support for string view arguments to url() is deprecated and will be removed in Django 1.10 (got mysite.views.first_page). Pass the callable instead.
url(r'^$', 'mysite.views.first_page'),`

`/home/vagrant/mysite/west/urls.py:4: RemovedInDjango110Warning: Support for string view arguments to url() is deprecated and will be removed in Django 1.10 (got west.views.first_page). Pass the callable instead.
url(r'^$', 'west.views.first_page'),`

`/home/vagrant/mysite/west/urls.py:4: RemovedInDjango110Warning: django.conf.urls.patterns() is deprecated and will be removed in Django 1.10. Update your urlpatterns to be a list of django.conf.urls.url() instances instead.
url(r'^$', 'west.views.first_page'),`

`/home/vagrant/mysite/mysite/urls.py:37: RemovedInDjango110Warning: django.conf.urls.patterns() is deprecated and will be removed in Django 1.10. Update your urlpatterns to be a list of django.conf.urls.url() instances instead.
url(r'^west/', include('west.urls')),`

`Operations to perform:
Apply all migrations: admin, contenttypes, auth, sessions
Running migrations:
Rendering model states... DONE
Applying contenttypes.0001_initial... OK
Applying auth.0001_initial... OK
Applying admin.0001_initial... OK
Applying admin.0002_logentry_remove_auto_add... OK
Applying contenttypes.0002_remove_content_type_name... OK
Applying auth.0002_alter_permission_name_max_length... OK
Applying auth.0003_alter_user_email_max_length... OK
Applying auth.0004_alter_user_username_opts... OK
Applying auth.0005_alter_user_last_login_null... OK
Applying auth.0006_require_contenttypes_0002... OK
Applying auth.0007_alter_validators_add_error_messages... OK
Applying sessions.0001_initial... OK`

我看字面意思是 我这种 url()写法在 Django 1.10 中不支持了 而且会被移除
那请问 正确的写法是什么 谢谢
urls.py 我这里这样写的
‘ from django.conf.urls import patterns, include, url

from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^$', 'mysite.views.first_page'),
url(r'^west/', include('west.urls')),
)‘
7503 次点击
所在节点    Python
3 条回复
Changxu
2015-12-03 13:54:14 +08:00
from views import first_page

....
url(r'^$', first_page),
....

文档那个英文句子的意思是 1.10 里 url 的视图路径不能用字符串字面值(string literal)了
lenciel
2015-12-03 23:08:03 +08:00
1. 你在用没有正式 release 的 django 版本,这样不好(最新的 stable 的版本应该是 1.9 )
2. 遇到`RemovedInDjango110Warning`这种错,你都可以查文档,比如`url()`的最新版本的文档:
http://django.readthedocs.org/en/latest/ref/urls.html#url
Banio
2015-12-07 08:39:33 +08:00
@lenciel 谢谢 我用的是 1.9 版本的 Django 我看看文档

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/240841

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX