से URL का पहला भाग प्राप्त करें I request.path
का उपयोग करें। उदाहरण के लिए यदि वर्तमान यूआरएल "/ test/foo/baz" है, तो मैं जानना चाहता हूं कि यह स्ट्रिंग अनुक्रम के साथ शुरू होता है, मान लें/परीक्षण करें। अगर मैं इस्तेमाल करने की कोशिश:वर्तमान URL प्राप्त करने के लिए Django टेम्पलेट
{% if request.path.startswith('/test') %}
Test
{% endif %}
मैं एक त्रुटि कह रही है कि यह अभिव्यक्ति के शेष पार्स नहीं कर सके मिलती है:
Could not parse the remainder: '('/test')' from 'request.path.startswith('/test')'
Request Method: GET
Request URL: http://localhost:8021/test/foo/baz/
Exception Type: TemplateSyntaxError
Exception Value:
Could not parse the remainder: '('/test')' from 'request.path.startswith('/test')'
Exception Location: C:\Python25\lib\site-packages\django\template\__init__.py in __init__, line 528
Python Executable: C:\Python25\python.exe
Python Version: 2.5.4
Template error
एक समाधान काम करने के लिए एक कस्टम टैग बनाने के लिए किया जाएगा। क्या मेरी समस्या को हल करने के लिए कुछ और मौजूद है? इस्तेमाल किया Django संस्करण 1.0.4 है।
मुझे 'अगर' कथन अनुचित रूप से त्रुटियों को स्वरूपित करता है। – Seitaridis
मेरे लिए यह ठीक काम कर रहा है – Ted
आपका पहला समाधान ठीक काम करता है! :) –