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
6348db37
Kaydet (Commit)
6348db37
authored
Eyl 29, 2015
tarafından
Tim Graham
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Refs #22384 -- Removed obsolete code for the removal of reversing by dotted path.
üst
53ccffdb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
57 deletions
+19
-57
defaulttags.py
django/template/defaulttags.py
+19
-57
No files found.
django/template/defaulttags.py
Dosyayı görüntüle @
6348db37
...
...
@@ -437,30 +437,14 @@ class URLNode(Node):
current_app
=
context
.
request
.
resolver_match
.
namespace
except
AttributeError
:
current_app
=
None
# Try to look up the URL twice: once given the view name, and again
# relative to what we guess is the "main" app. If they both fail,
# re-raise the NoReverseMatch unless we're using the
# {% url ... as var %} construct in which case return nothing.
# Try to look up the URL. If it fails, raise NoReverseMatch unless the
# {% url ... as var %} construct is used, in which case return nothing.
url
=
''
try
:
url
=
reverse
(
view_name
,
args
=
args
,
kwargs
=
kwargs
,
current_app
=
current_app
)
except
NoReverseMatch
:
exc_info
=
sys
.
exc_info
()
if
settings
.
SETTINGS_MODULE
:
project_name
=
settings
.
SETTINGS_MODULE
.
split
(
'.'
)[
0
]
try
:
url
=
reverse
(
project_name
+
'.'
+
view_name
,
args
=
args
,
kwargs
=
kwargs
,
current_app
=
current_app
)
except
NoReverseMatch
:
if
self
.
asvar
is
None
:
# Re-raise the original exception, not the one with
# the path relative to the project. This makes a
# better error message.
six
.
reraise
(
*
exc_info
)
else
:
if
self
.
asvar
is
None
:
raise
if
self
.
asvar
is
None
:
raise
if
self
.
asvar
:
context
[
self
.
asvar
]
=
url
...
...
@@ -1300,61 +1284,40 @@ def templatetag(parser, token):
@register.tag
def
url
(
parser
,
token
):
"""
Return
s an absolute URL matching
given view with its parameters.
Return
an absolute URL matching the
given view with its parameters.
This is a way to define links that aren't tied to a particular URL
configuration::
{
%
url "
path.to.some_view
" arg1 arg2
%
}
{
%
url "
url_name
" arg1 arg2
%
}
or
{
%
url "path.to.some_view" name1=value1 name2=value2
%
}
The first argument is a path to a view. It can be an absolute Python path
or just ``app_name.view_name`` without the project name if the view is
located inside the project.
Other arguments are space-separated values that will be filled in place of
positional and keyword arguments in the URL. Don't mix positional and
keyword arguments.
{
%
url "url_name" name1=value1 name2=value2
%
}
All arguments for the URL should be present.
The first argument is a django.conf.urls.url() name. Other arguments are
space-separated values that will be filled in place of positional and
keyword arguments in the URL. Don't mix positional and keyword arguments.
All arguments for the URL must be present.
For example
if you have a view ``app_name.client`` taking client's id and
the corresponding line in a URLconf looks like this::
For example
, if you have a view ``app_name.views.client_details`` taking
the c
lient's id and the c
orresponding line in a URLconf looks like this::
('^client/(
\
d+)/$', 'app_name.client
')
url('^client/(
\
d+)/$', views.client_details, name='client-detail-view
')
and this app's URLconf is included into the project's URLconf under some
path::
('^clients/', include('project_name.
app_name.urls'))
url('^clients/', include('
app_name.urls'))
then in a template you can create a link for a certain client like this::
{
%
url "app_name.client" client.id
%
}
The URL will look like ``/clients/client/123/``.
The first argument can also be a named URL instead of the Python path to
the view callable. For example if the URLconf entry looks like this::
url('^client/(
\
d+)/$', name='client-detail-view')
then in the template you can use::
{
%
url "client-detail-view" client.id
%
}
There is even another possible value type for the first argument. It can be
the name of a template variable that will be evaluated to obtain the view
name or the URL name, e.g.::
{
%
with view_path="app_name.client"
%
}
{
%
url view_path client.id
%
}
{
%
endwith
%
}
The URL will look like ``/clients/client/123/``.
or,
The first argument may also be the name of a template variable that will be
evaluated to obtain the view name or the URL name, e.g.::
{
%
with url_name="client-detail-view"
%
}
{
%
url url_name client.id
%
}
...
...
@@ -1362,8 +1325,7 @@ def url(parser, token):
"""
bits
=
token
.
split_contents
()
if
len
(
bits
)
<
2
:
raise
TemplateSyntaxError
(
"'
%
s' takes at least one argument"
" (path to a view)"
%
bits
[
0
])
raise
TemplateSyntaxError
(
"'
%
s' takes at least one argument, the name of a url()."
%
bits
[
0
])
viewname
=
parser
.
compile_filter
(
bits
[
1
])
args
=
[]
kwargs
=
{}
...
...
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