我在基于类的视图中使用以下代码
from django.core.urlresolvers import reverse_lazy
url = reverse('url_name')
urls.py
看起来如下
from django.conf.urls import patterns, url
from myapp import views
urlpatterns = patterns('',
url(r'^$', views.TestView.as_view(), name='url_name'),
)
这样做时,我收到了弃用警告:
DeprecationWarning: Function-based generic views have been deprecated; use class-based views instead.
DeprecationWarning
警告在“django/views/generic/simple.py:8”上引发
这是一个堆栈,看看发生了什么:
-> return urlresolvers.reverse('url_name')
/home/vagrant/.virtualenvs/wfp/lib/python2.5/site-packages/django/core/urlresolvers.py(476)reverse()
-> return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs))
/home/vagrant/.virtualenvs/wfp/lib/python2.5/site-packages/django/core/urlresolvers.py(363)_reverse_with_prefix()
-> possibilities = self.reverse_dict.getlist(lookup_view)
/home/vagrant/.virtualenvs/wfp/lib/python2.5/site-packages/django/core/urlresolvers.py(276)reverse_dict()
-> self._populate()
/home/vagrant/.virtualenvs/wfp/lib/python2.5/site-packages/django/core/urlresolvers.py(265)_populate()
-> lookups.appendlist(pattern.callback, (bits, p_pattern, pattern.default_args))
/home/vagrant/.virtualenvs/wfp/lib/python2.5/site-packages/django/core/urlresolvers.py(216)callback()
-> self._callback = get_callable(self._callback_str)
/home/vagrant/.virtualenvs/wfp/lib/python2.5/site-packages/django/utils/functional.py(27)wrapper()
-> result = func(*args)
/home/vagrant/.virtualenvs/wfp/lib/python2.5/site-packages/django/core/urlresolvers.py(92)get_callable()
-> lookup_view = getattr(import_module(mod_name), func_name)
/home/vagrant/.virtualenvs/wfp/lib/python2.5/site-packages/django/utils/importlib.py(35)import_module()
-> __import__(name)
> /home/vagrant/.virtualenvs/wfp/lib/python2.5/site-packages/django/views/generic/simple.py(6)<module>()
-> import warnings
未来的方法是什么?我目前正在使用 Django 1.4。