Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
7b6e4208
Kaydet (Commit)
7b6e4208
authored
Şub 11, 2017
tarafından
Tim Graham
Kaydeden (comit)
GitHub
Şub 11, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #25978 -- Deprecated shorcuts.render_to_response().
üst
0166dd2f
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
58 additions
and
36 deletions
+58
-36
shortcuts.py
django/shortcuts.py
+8
-0
deprecation.txt
docs/internals/deprecation.txt
+2
-0
2.0.txt
docs/releases/2.0.txt
+4
-0
shortcuts.txt
docs/topics/http/shortcuts.txt
+3
-1
test_render_to_response.py
tests/shortcuts/test_render_to_response.py
+39
-0
tests.py
tests/shortcuts/tests.py
+2
-35
No files found.
django/shortcuts.py
Dosyayı görüntüle @
7b6e4208
...
@@ -3,11 +3,14 @@ This module collects helper functions and classes that "span" multiple levels
...
@@ -3,11 +3,14 @@ This module collects helper functions and classes that "span" multiple levels
of MVC. In other words, these functions/classes introduce controlled coupling
of MVC. In other words, these functions/classes introduce controlled coupling
for convenience's sake.
for convenience's sake.
"""
"""
import
warnings
from
django.http
import
(
from
django.http
import
(
Http404
,
HttpResponse
,
HttpResponsePermanentRedirect
,
HttpResponseRedirect
,
Http404
,
HttpResponse
,
HttpResponsePermanentRedirect
,
HttpResponseRedirect
,
)
)
from
django.template
import
loader
from
django.template
import
loader
from
django.urls
import
NoReverseMatch
,
reverse
from
django.urls
import
NoReverseMatch
,
reverse
from
django.utils.deprecation
import
RemovedInDjango30Warning
from
django.utils.encoding
import
force_text
from
django.utils.encoding
import
force_text
from
django.utils.functional
import
Promise
from
django.utils.functional
import
Promise
...
@@ -17,6 +20,11 @@ def render_to_response(template_name, context=None, content_type=None, status=No
...
@@ -17,6 +20,11 @@ def render_to_response(template_name, context=None, content_type=None, status=No
Returns a HttpResponse whose content is filled with the result of calling
Returns a HttpResponse whose content is filled with the result of calling
django.template.loader.render_to_string() with the passed arguments.
django.template.loader.render_to_string() with the passed arguments.
"""
"""
warnings
.
warn
(
'render_to_response() is deprecated in favor render(). It has the '
'same signature except that it also requires a request.'
,
RemovedInDjango30Warning
,
stacklevel
=
2
,
)
content
=
loader
.
render_to_string
(
template_name
,
context
,
using
=
using
)
content
=
loader
.
render_to_string
(
template_name
,
context
,
using
=
using
)
return
HttpResponse
(
content
,
content_type
,
status
)
return
HttpResponse
(
content
,
content_type
,
status
)
...
...
docs/internals/deprecation.txt
Dosyayı görüntüle @
7b6e4208
...
@@ -17,6 +17,8 @@ details on these changes.
...
@@ -17,6 +17,8 @@ details on these changes.
* The ``django.db.backends.postgresql_psycopg2`` module will be removed.
* The ``django.db.backends.postgresql_psycopg2`` module will be removed.
* ``django.shortcuts.render_to_response()`` will be removed.
.. _deprecation-removed-in-2.1:
.. _deprecation-removed-in-2.1:
2.1
2.1
...
...
docs/releases/2.0.txt
Dosyayı görüntüle @
7b6e4208
...
@@ -297,6 +297,10 @@ Miscellaneous
...
@@ -297,6 +297,10 @@ Miscellaneous
``'django.db.backends.postgresql_psycopg2'``, though you can simplify that by
``'django.db.backends.postgresql_psycopg2'``, though you can simplify that by
using the ``'django.db.backends.postgresql'`` name added in Django 1.9.
using the ``'django.db.backends.postgresql'`` name added in Django 1.9.
* ``django.shortcuts.render_to_response()`` is deprecated in favor of
:func:`django.shortcuts.render`. ``render()`` takes the same arguments
except that is also requires a ``request``.
.. _removed-features-2.0:
.. _removed-features-2.0:
Features removed in 2.0
Features removed in 2.0
...
...
docs/topics/http/shortcuts.txt
Dosyayı görüntüle @
7b6e4208
...
@@ -86,9 +86,11 @@ This example is equivalent to::
...
@@ -86,9 +86,11 @@ This example is equivalent to::
.. function:: render_to_response(template_name, context=None, content_type=None, status=None, using=None)
.. function:: render_to_response(template_name, context=None, content_type=None, status=None, using=None)
.. deprecated:: 2.0
This function preceded the introduction of :func:`render` and works
This function preceded the introduction of :func:`render` and works
similarly except that it doesn't make the ``request`` available in the
similarly except that it doesn't make the ``request`` available in the
response.
It's not recommended and is likely to be deprecated in the future.
response.
``redirect()``
``redirect()``
==============
==============
...
...
tests/shortcuts/test_render_to_response.py
0 → 100644
Dosyayı görüntüle @
7b6e4208
from
django.test
import
SimpleTestCase
,
ignore_warnings
,
override_settings
from
django.test.utils
import
require_jinja2
from
django.utils.deprecation
import
RemovedInDjango30Warning
@ignore_warnings
(
category
=
RemovedInDjango30Warning
)
@override_settings
(
ROOT_URLCONF
=
'shortcuts.urls'
)
class
RenderToResponseTests
(
SimpleTestCase
):
def
test_render_to_response
(
self
):
response
=
self
.
client
.
get
(
'/render_to_response/'
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
content
,
b
'FOO.BAR..
\n
'
)
self
.
assertEqual
(
response
[
'Content-Type'
],
'text/html; charset=utf-8'
)
def
test_render_to_response_with_multiple_templates
(
self
):
response
=
self
.
client
.
get
(
'/render_to_response/multiple_templates/'
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
content
,
b
'FOO.BAR..
\n
'
)
def
test_render_to_response_with_content_type
(
self
):
response
=
self
.
client
.
get
(
'/render_to_response/content_type/'
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
content
,
b
'FOO.BAR..
\n
'
)
self
.
assertEqual
(
response
[
'Content-Type'
],
'application/x-rendertest'
)
def
test_render_to_response_with_status
(
self
):
response
=
self
.
client
.
get
(
'/render_to_response/status/'
)
self
.
assertEqual
(
response
.
status_code
,
403
)
self
.
assertEqual
(
response
.
content
,
b
'FOO.BAR..
\n
'
)
@require_jinja2
def
test_render_to_response_with_using
(
self
):
response
=
self
.
client
.
get
(
'/render_to_response/using/'
)
self
.
assertEqual
(
response
.
content
,
b
'DTL
\n
'
)
response
=
self
.
client
.
get
(
'/render_to_response/using/?using=django'
)
self
.
assertEqual
(
response
.
content
,
b
'DTL
\n
'
)
response
=
self
.
client
.
get
(
'/render_to_response/using/?using=jinja2'
)
self
.
assertEqual
(
response
.
content
,
b
'Jinja2
\n
'
)
tests/shortcuts/tests.py
Dosyayı görüntüle @
7b6e4208
...
@@ -2,41 +2,8 @@ from django.test import SimpleTestCase, override_settings
...
@@ -2,41 +2,8 @@ from django.test import SimpleTestCase, override_settings
from
django.test.utils
import
require_jinja2
from
django.test.utils
import
require_jinja2
@override_settings
(
@override_settings
(
ROOT_URLCONF
=
'shortcuts.urls'
)
ROOT_URLCONF
=
'shortcuts.urls'
,
class
RenderTests
(
SimpleTestCase
):
)
class
ShortcutTests
(
SimpleTestCase
):
def
test_render_to_response
(
self
):
response
=
self
.
client
.
get
(
'/render_to_response/'
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
content
,
b
'FOO.BAR..
\n
'
)
self
.
assertEqual
(
response
[
'Content-Type'
],
'text/html; charset=utf-8'
)
def
test_render_to_response_with_multiple_templates
(
self
):
response
=
self
.
client
.
get
(
'/render_to_response/multiple_templates/'
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
content
,
b
'FOO.BAR..
\n
'
)
def
test_render_to_response_with_content_type
(
self
):
response
=
self
.
client
.
get
(
'/render_to_response/content_type/'
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
content
,
b
'FOO.BAR..
\n
'
)
self
.
assertEqual
(
response
[
'Content-Type'
],
'application/x-rendertest'
)
def
test_render_to_response_with_status
(
self
):
response
=
self
.
client
.
get
(
'/render_to_response/status/'
)
self
.
assertEqual
(
response
.
status_code
,
403
)
self
.
assertEqual
(
response
.
content
,
b
'FOO.BAR..
\n
'
)
@require_jinja2
def
test_render_to_response_with_using
(
self
):
response
=
self
.
client
.
get
(
'/render_to_response/using/'
)
self
.
assertEqual
(
response
.
content
,
b
'DTL
\n
'
)
response
=
self
.
client
.
get
(
'/render_to_response/using/?using=django'
)
self
.
assertEqual
(
response
.
content
,
b
'DTL
\n
'
)
response
=
self
.
client
.
get
(
'/render_to_response/using/?using=jinja2'
)
self
.
assertEqual
(
response
.
content
,
b
'Jinja2
\n
'
)
def
test_render
(
self
):
def
test_render
(
self
):
response
=
self
.
client
.
get
(
'/render/'
)
response
=
self
.
client
.
get
(
'/render/'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment