1
0
mirror of https://github.com/django/django.git synced 2025-10-24 14:16:09 +00:00

Fixed #26013 -- Moved django.core.urlresolvers to django.urls.

Thanks to Tim Graham for the review.
This commit is contained in:
Marten Kenbeek
2015-12-30 16:51:16 +01:00
committed by Tim Graham
parent df3d5b1d73
commit 16411b8400
117 changed files with 961 additions and 922 deletions

View File

@@ -98,7 +98,7 @@ First we need to add :meth:`~django.db.models.Model.get_absolute_url()` to our
.. snippet::
:filename: models.py
from django.core.urlresolvers import reverse
from django.urls import reverse
from django.db import models
class Author(models.Model):
@@ -115,7 +115,7 @@ here; we don't have to write any logic ourselves:
:filename: views.py
from django.views.generic.edit import CreateView, UpdateView, DeleteView
from django.core.urlresolvers import reverse_lazy
from django.urls import reverse_lazy
from myapp.models import Author
class AuthorCreate(CreateView):
@@ -131,8 +131,8 @@ here; we don't have to write any logic ourselves:
success_url = reverse_lazy('author-list')
.. note::
We have to use :func:`~django.core.urlresolvers.reverse_lazy` here, not
just ``reverse`` as the urls are not loaded when the file is imported.
We have to use :func:`~django.urls.reverse_lazy` here, not just
``reverse()`` as the urls are not loaded when the file is imported.
The ``fields`` attribute works the same way as the ``fields`` attribute on the
inner ``Meta`` class on :class:`~django.forms.ModelForm`. Unless you define the

View File

@@ -225,7 +225,7 @@ We'll demonstrate this with the ``Author`` model we used in the
:filename: views.py
from django.http import HttpResponseForbidden, HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.urls import reverse
from django.views.generic import View
from django.views.generic.detail import SingleObjectMixin
from books.models import Author
@@ -445,7 +445,7 @@ Our new ``AuthorDetail`` looks like this::
from django import forms
from django.http import HttpResponseForbidden
from django.core.urlresolvers import reverse
from django.urls import reverse
from django.views.generic import DetailView
from django.views.generic.edit import FormMixin
from books.models import Author
@@ -541,7 +541,7 @@ can find the author we're talking about, and we have to remember to set
``template_name`` to ensure that form errors will render the same
template as ``AuthorDisplay`` is using on ``GET``::
from django.core.urlresolvers import reverse
from django.urls import reverse
from django.http import HttpResponseForbidden
from django.views.generic import FormView
from django.views.generic.detail import SingleObjectMixin

View File

@@ -103,9 +103,8 @@ This example is equivalent to::
* A model: the model's :meth:`~django.db.models.Model.get_absolute_url()`
function will be called.
* A view name, possibly with arguments: :func:`urlresolvers.reverse
<django.core.urlresolvers.reverse>` will be used to reverse-resolve the
name.
* A view name, possibly with arguments: :func:`~django.urls.reverse` will be
used to reverse-resolve the name.
* An absolute or relative URL, which will be used as-is for the redirect
location.
@@ -131,7 +130,7 @@ You can use the :func:`redirect` function in a number of ways.
2. By passing the name of a view and optionally some positional or
keyword arguments; the URL will be reverse resolved using the
:func:`~django.core.urlresolvers.reverse` method::
:func:`~django.urls.reverse` method::
def my_view(request):
...

View File

@@ -533,8 +533,7 @@ layers where URLs are needed:
* In templates: Using the :ttag:`url` template tag.
* In Python code: Using the :func:`django.core.urlresolvers.reverse`
function.
* In Python code: Using the :func:`~django.urls.reverse` function.
* In higher level code related to handling of URLs of Django model instances:
The :meth:`~django.db.models.Model.get_absolute_url` method.
@@ -571,7 +570,7 @@ You can obtain these in template code by using:
Or in Python code::
from django.core.urlresolvers import reverse
from django.urls import reverse
from django.http import HttpResponseRedirect
def redirect_to_year(request):
@@ -671,8 +670,8 @@ the fully qualified name into parts and then tries the following lookup:
2. If there is a current application defined, Django finds and returns the URL
resolver for that instance. The current application can be specified with
the ``current_app`` argument to the
:func:`~django.core.urlresolvers.reverse()` function.
the ``current_app`` argument to the :func:`~django.urls.reverse()`
function.
The :ttag:`url` template tag uses the namespace of the currently resolved
view as the current application in a

View File

@@ -1360,7 +1360,7 @@ After defining these URL patterns, Django will automatically add the
language prefix to the URL patterns that were added by the ``i18n_patterns``
function. Example::
from django.core.urlresolvers import reverse
from django.urls import reverse
from django.utils.translation import activate
>>> activate('en')
@@ -1414,11 +1414,10 @@ URL patterns can also be marked translatable using the
url(_(r'^news/'), include(news_patterns, namespace='news')),
)
After you've created the translations, the
:func:`~django.core.urlresolvers.reverse` function will return the URL in the
active language. Example::
After you've created the translations, the :func:`~django.urls.reverse`
function will return the URL in the active language. Example::
from django.core.urlresolvers import reverse
from django.urls import reverse
from django.utils.translation import activate
>>> activate('en')

View File

@@ -411,7 +411,7 @@ For example, you can create ``myproject/jinja2.py`` with this content::
from __future__ import absolute_import # Python 2 only
from django.contrib.staticfiles.storage import staticfiles_storage
from django.core.urlresolvers import reverse
from django.urls import reverse
from jinja2 import Environment

View File

@@ -507,9 +507,8 @@ Specifically, a ``Response`` object has the following attributes:
.. attribute:: resolver_match
An instance of :class:`~django.core.urlresolvers.ResolverMatch` for the
response. You can use the
:attr:`~django.core.urlresolvers.ResolverMatch.func` attribute, for
An instance of :class:`~django.urls.ResolverMatch` for the response.
You can use the :attr:`~django.urls.ResolverMatch.func` attribute, for
example, to verify the view that served the response::
# my_view here is a function based view
@@ -520,7 +519,7 @@ Specifically, a ``Response`` object has the following attributes:
self.assertEqual(response.resolver_match.func.__name__, MyView.as_view().__name__)
If the given URL is not found, accessing this attribute will raise a
:exc:`~django.core.urlresolvers.Resolver404` exception.
:exc:`~django.urls.Resolver404` exception.
You can also use dictionary syntax on the response object to query the value
of any settings in the HTTP headers. For example, you could determine the