简体   繁体   中英

django 1.3 template tag url unexpected result

template:

            <!-- Images slide as a row starts -->
            <!-- power.views.IMAGE_SLIDES_ROW returns image_slider_row/   -->
            {% url power.views.IMAGE_SLIDES_ROW %} 
            <!-- Images as a row Ends -->

url conf:

     url(r'^image_slider_row/', views.images_slider_row_func, name='image_slider_row'),

View :

def images_slider_row(request):
    print "Debug-1"
    return render_to_response('images_slider_row.html', {})

actually I am expecting "images_slider_row_func" will get call on url tag execution but it is not happening, it is showing following string in the browser

/images_slider_row/

am I missing anything or am I misunderstood the concept? Please help me for fixing this issue.

Basically, the url method takes the parameters for the regular expression matching the accessed URL, the function to call (in this case, images_slider_row_func) and with the keyword arg name the name that can be used as shown in your template to identify that function when calling the url "macro".

However, django should try to access the function "images_slider_row_func" when accessing the URL "/images_slider_row/" (notice the difference here!)

使用<a href="{% url image_slider_row %}">foo bar</a>作为示例,templatetag url期望urls.py来自您的name参数

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM