3š
Instead of using a slice assignment to grow a list
embed_list[len(embed_list):] = [foo]
you should probably just do
embed_list.append(foo)
But really you should try unescaping html with a library function rather than doing it yourself.
That NoneType error sounds like embed.replace is None at some point, which only makes sense if your list is not a list of strings ā you might want to double-check that with some asserts or something similar.
8š
I am quite sure that Django templates does not support that.
For your replace operation I would look into different filters.
You really should try to keep as much logic as you can in your views and not in the templates.
- [Django]-How do you produce/create tables in Geraldo Reports?
- [Django]-Django Test ā South migration reports 'no such table' but I can see said table in the db
7š
Djangoās template language is deliberately hobbled. When used by non-programming designers, this is definitely a Good Thing, but there are times when you need to do a little programming. (No, I donāt want to argue about that. This has come up several times on django-users and django-dev.)
Two ways to accomplish what you were trying:
- Use a different template engine. See Jinja2 for a good example that is fully explained for integrating with Django.
- Use a template tag that permits you to do Python expressions. See limodouās Expr tag.
I have used the expr tag in several places and it has made life much easier. My next major Django site will use jinja2.
- [Django]-Why does the Django Atom1Feed use atom:updated instead of atom:published?
- [Django]-Ckeditor_uploader Dynamic Image Upload Path
4š
I donāt see why youād get āNoneType object is not callableā. That should mean that somewhere on the line is an expression like āfoo(ā¦)ā, and it means foo is None.
BTW: You are trying to extend the embed_list, and itās easier to do it like this:
embed_list = []
for embed in embeds:
embed_list.append(embed.replace("<", "<")) #this is line 35
return render_to_response("scanvideos.html", {"embed_list":embed_list})
and even easier to use a list comprehension:
embed_list = [embed.replace("<", "<") for embed in embeds]
- [Django]-Django Templates ā how do I output the relative path of file when using a FilePathField recursively
- [Django]-Add CSS class to django RadioSelect label
- [Django]-Django Forms for generic relationships. How to include them?
- [Django]-Django Postgresql syncdb error
- [Django]-Architecture for syncing s3/cloudfront with database
3š
Django templates use their own syntax, not like Kid or Genshi.
You have to roll your own Custom Template Tag.
I guess the main reason is enforcing good practice. In my case, Iāve already a hard time explaining those special templates tags to the designer on our team. If it was plain Python Iām pretty sure we wouldnāt have chosen Django at all. I think thereās also a performance issue, Django templates benchmarks are fast, while last time I checked genshi was much slower. I donāt know if itās due to freely embedded Python, though.
You either need to review your approach and write your own custom templates (more or less synonyms to āhelpersā in Ruby on Rails), or try another template engine.
For your edit, thereās a better syntax in Python:
embed_list.append(embed.replace("<", "<"))
I donāt know if itāll fix your error, but at least itās less JavaScriptesque š
Edit 2: Django automatically escapes all variables. You can enforce raw HTML with |safe filter : {{embed|safe}}
.
Youād better take some time reading the documentation, which is really great and useful.