If anyone has any pointers as to what might be the problem please answer. I would greatly appreciate any help you maybe able to provide.
Thanks. nav On Oct 17, 11:44 pm, nav <navanitach...@gmail.com> wrote: > Dear Folks, > > I am using a number of subdomains for my website and decided to create > a custom url tag and try as shown on > > http://stackoverflow.com/questions/3461806/django-subdomains-and-mod-... > > My template tag being used in my template like this: > <a href='{% subdomainurl "app.views.view_decider" "about" %}'>About > Us</a> > > My template tags functions looks like this: > > class SubdomainURLNode(URLNode): > def render(self, context): > request = context['request'] > domain = request.get_host() > subdomain = re.sub(r'^www\.','',domain).split('.')[0] > path = super(SubdomainURLNode, self).render(context) > return "%s/%s" % (str(request.get_host()), path) > > @register.tag > def subdomainurl(parser, token, node_cls=SubdomainURLNode): > """Just like {% url %} but checks for a subdomain.""" > node_instance = url(parser, token) > return node_cls(view_name=node_instance.view_name, > args=node_instance.args, > kwargs=node_instance.kwargs, > asvar=node_instance.asvar) > > While trying to render the template tag it comes back saying: > > TemplateSyntaxError at / > > Caught TypeError while rendering: cannot concatenate 'str' and > 'FilterExpression' objects > > My template tag function does not return the path value from the > statement: > path = super(SubdomainURLNode, self).render(context) > > because the URLNode function fails on line 442 because of a type > mismatch: > url = reverse(project_name + '.' + view_name, > > I just tried using the standard url method in django {% url > "app.views.view_decider" "about" %} and this works. I would like to > know where I am going wrong with my function so I can get this to > work. > > The full traceback of the error is below: > > Thanks in advance. > nav > > The full traceback of the error is below: > ------------------------------------------------------------------ > Environment: > > Request Method: GET > Request URL:http://localhost:8000/ > > Django Version: 1.3.1 > Python Version: 2.6.6 > Installed Applications: > ['django.contrib.auth', > 'django.contrib.contenttypes', > 'django.contrib.sessions', > 'django.contrib.sites', > 'django.contrib.messages', > 'django.contrib.staticfiles', > 'django.contrib.admin', > 'swanlotus_site', > 'south'] > Installed Middleware: > ('django.middleware.common.CommonMiddleware', > 'django.contrib.sessions.middleware.SessionMiddleware', > 'django.middleware.csrf.CsrfViewMiddleware', > 'django.contrib.auth.middleware.AuthenticationMiddleware', > 'django.contrib.messages.middleware.MessageMiddleware', > 'middleware.SubdomainMiddleware') > > Template error: > In template /home/nandu/django/swanlotus/templates/navigation.html, > error at line 6 > Caught TypeError while rendering: cannot concatenate 'str' and > 'FilterExpression' objects > 1 : {% load custom_tags %} > > 2 : {% load url from future %} > > 3 : <ul> > > 4 : <li><a href="http://localhost:8000/">Home</a></li> > > 5 : <!-- <li><a href="http://localhost:8000/about">About Us</a> > --> > > 6 : <li><a href=' {% subdomainurl > "swanlotus_site.views.view_decider" "about" %} '>About Us</a> > > 7 : <ul> > > 8 : <li><a href="http://chandra.localhost: > 8000">Chandra</a></li> > > 9 : </ul> > > 10 : </li> > > 11 : <li><a href="http://downloads.localhost:8000">Downloads</ > a> > > 12 : {% if thesis and phd_guide%} > > 13 : <ul> > > 14 : <li><a href="http://downloads.localhost:8000/ > #thesis">Thesis Writing</a></li> > > 15 : <li><a href="http://downloads.localhost:8000/ > #phd">PhD Guide</a></li> > > 16 : {% if calculus_sheet and app_maths_sheet %} > > Traceback: > File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/ > base.py" in get_response > 111. response = callback(request, > *callback_args, **callback_kwargs) > File "/home/nandu/django/swanlotus/swanlotus_site/views.py" in > view_decider > 21. return render(request, template, context) > File "/usr/local/lib/python2.6/dist-packages/django/shortcuts/ > __init__.py" in render > 44. return HttpResponse(loader.render_to_string(*args, > **kwargs), > File "/usr/local/lib/python2.6/dist-packages/django/template/ > loader.py" in render_to_string > 188. return t.render(context_instance) > File "/usr/local/lib/python2.6/dist-packages/django/template/base.py" > in render > 123. return self._render(context) > File "/usr/local/lib/python2.6/dist-packages/django/template/base.py" > in _render > 117. return self.nodelist.render(context) > File "/usr/local/lib/python2.6/dist-packages/django/template/base.py" > in render > 744. bits.append(self.render_node(node, context)) > File "/usr/local/lib/python2.6/dist-packages/django/template/debug.py" > in render_node > 73. result = node.render(context) > File "/usr/local/lib/python2.6/dist-packages/django/template/ > loader_tags.py" in render > 127. return compiled_parent._render(context) > File "/usr/local/lib/python2.6/dist-packages/django/template/base.py" > in _render > 117. return self.nodelist.render(context) > File "/usr/local/lib/python2.6/dist-packages/django/template/base.py" > in render > 744. bits.append(self.render_node(node, context)) > File "/usr/local/lib/python2.6/dist-packages/django/template/debug.py" > in render_node > 73. result = node.render(context) > File "/usr/local/lib/python2.6/dist-packages/django/template/ > loader_tags.py" in render > 159. return self.render_template(self.template, context) > File "/usr/local/lib/python2.6/dist-packages/django/template/ > loader_tags.py" in render_template > 141. output = template.render(context) > File "/usr/local/lib/python2.6/dist-packages/django/template/base.py" > in render > 123. return self._render(context) > File "/usr/local/lib/python2.6/dist-packages/django/template/base.py" > in _render > 117. return self.nodelist.render(context) > File "/usr/local/lib/python2.6/dist-packages/django/template/base.py" > in render > 744. bits.append(self.render_node(node, context)) > File "/usr/local/lib/python2.6/dist-packages/django/template/debug.py" > in render_node > 73. result = node.render(context) > File "/home/nandu/django/swanlotus/swanlotus_site/templatetags/ > custom_tags.py" in render > 16. path = super(SubdomainURLNode, self).render(context) > File "/usr/local/lib/python2.6/dist-packages/django/template/ > defaulttags.py" in render > 442. url = reverse(project_name + '.' + > view_name, > > Exception Type: TemplateSyntaxError at / > Exception Value: Caught TypeError while rendering: cannot concatenate > 'str' and 'FilterExpression' objects -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.