django template "file name too long"
I'm very new to Python and Django so maybe someone can point me in the right direction.
I have the following url.py line
url(r'^$', direct_to_template,
{'template':'index.html',
'extra_context':{'featured_actors': lambda: User.objects
.annotate(avatars_nb=Count('avatar'))
.filter(actor_profile__is_featured=True, avatars_nb__gt=0)
.order_by('?')[:4]},
}, name='index'),
All this was working perfectly fine for a long time but for no reason that I can see all of a sudden I'm getting this template error.
TemplateSyntaxError at /
Caught an exception while rendering: (36, 'File name too long')
On line 70
66 {% if featured_actors|length %}
67 <div id="featured">
68 <h2>Featured Actors: </h2>
69 <ul>
70 {% for actor in featured_actors %}
71 <li>
72 <a href="{% url public_profile actor.username %}">
73 <img src="{% avatar_itself_url actor.avatar_set.all.0 200 %}" alt="{{ actor.profile.firstname }} {{ actor.profile.lastname }}" style="max-width:140px" height="200"/>
74 </a>
75 </li>开发者_Python百科;
76 {% endfor %}
What is the best way to debug this?
UPDATE
126 def avatar_url(self, size):
127 return self.avatar.storage.url(self.avatar_name(size))
I think I found a bit of the problem, one of the user profiles is also giving the same error. So I think it must be a avatar/image path for him that is too long. I'm trying to narrow it down...
It's possible that the image path {% avatar_itself_url actor.avatar_set.all.0 200 %}
is too long. Can you delete the line with <img ...
and see if the template renders?
If the above renders, from the python manage.py shell
, can you verify the length of your image path? Is the length greater than 255 chars?
ANSWER TO COMMENT
Your image path is too long, by that I mean:
<img src="/this/is/a/very/long/path/which/exceeds/255/characters/something.png" />
The above is not 255 chars long but you get the idea. The above src path might be very long. Try to find out what that path is and calculate its length. What does the implementation of avatar_itself_url
look like? How about the unicode of Avatar
? What does it return? Do you have an Avatar with a very long name?
Replicating the error msg
Here's how you can replicate the error msg from python. Run the following in a python script:
long_filename = 'a' * 256
fp = open(long_filename, 'w')
fp.close()
The above should return the msg: IOError: [Errno 36] File name too long:
.
Displaying the image path
Can you replace the img tag from the html by just its content: {% avatar_itself_url actor.avatar_set.all.0 200 %}
? Instead of seeing the image, you should see the path of the image. Eyeballing the one longer than 256 chars shouldn't be an issue.
精彩评论