Hello, nav

The most relevant lines in your traceback are:


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 %}

   (...)

   6 :   <li><a href=' {% subdomainurl "swanlotus_site.views.view_decider"
"about" %} '>About Us</a>



File "/usr/local/lib/python2.6/dist-packages/django/template/defaulttags.py"
in render
  442.                     url = reverse(project_name + '.' + view_name,


Which basically means project_name and view_name cannot be concatenated (as
attempted on line 442 of defaulttags.py).

If I had to guess, I'd say the problem is due to the fact that you're
subclassing URLNode to create your custom {% subdomainurl %} tag, but also
trying to {% load url from future %}.

Loading the new url (which takes a string/variable as the first argument
rather than a constant [1]) could indeed lead you to believe {% subdomainurl
%} would behave the same way, but SubdomainURLNode (which is in your
custom_tags) actually subclasses the "old" (current) URLNode class.

If you want {% subdomainurl %} to be future-proof as well, then you will
need to either modify it to subclass django.templatetags.future.URLNode [2].
Another solution would be to create a second {% subdomainurl %}, that
inherits from future.URLNode. Perhaps you could even split your custom tags
into two separate libraries (one of them named custom_future or whatever)
and allow for a syntax similar to the one you use to load {% url %}.

On a side note, I'd recommend choosing a better name than "custom_tags"
because that sounds too generic. You can have as many templatetags modules
as you'd like, so don't be afraid to organize your tags in different files!

Let us know if you have any other questions and good luck.


Cheers,
AT

[1]
https://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs#url
[2]
https://code.djangoproject.com/browser/django/trunk/django/templatetags/future.py#L37



On Tue, Oct 18, 2011 at 12:06 PM, nav <navanitach...@gmail.com> wrote:

> AT,
>
> Thanks for your email I have posted the custom template tag code and
> the traceback at dpaste. The template code is at:
>
> http://dpaste.com/636570/
>
> the traceback is at:
>
> http://dpaste.com/636571/
>
> Please do let me know if anything else is required.
>
> Thanks,
> nav
>
> On Oct 18, 5:20 pm, Andre Terra <andrete...@gmail.com> wrote:
> > Please post your code again on something likehttp://dpaste.comand I'll
> > gladly take a look
> >
> > Cheers,
> > AT
> >
> > On Tue, Oct 18, 2011 at 9:43 AM, nav <navanitach...@gmail.com> wrote:
> > > 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
> todjango-us...@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.
>
> --
> 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.
>
>

-- 
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.

Reply via email to