The problem is that you have created a custom template filter, but you have saved it in views.py
, so django is treating it like a view. This is wrong - your code doesn't belong in views.py
and you don't need to add anything to urls.py
. To elaborate...
With your current configuration, when a request to your site root is picked up by the URLConf (via the '^$'
pattern you added), django expects the tracwiki()
function to return a HttpResponse
object - because it thinks that this is a view.
However if we look at this tracwiki()
function, you can see we do not return a HttpResponse
object via render()
or render_to_response()
etc. Instead we are returning a SafeText
object which does not have a .get()
attribute, unlike a HttpResponse
object, hence the exception when the middleware calls .get()
on the object we returned.
Instead you need to remove the line you added to your urls.py
, and use the template filter inside the appropriate HTML template where you want to render this markup. For example
{{ some_variable|tracwiki }}
If you are unfamiliar with template filters, here are some built-in filters being used.
You also need to move the tracwiki()
logic out of the views.py
file and into a new module inside a new templatags
directory. Read more about that in the docs (but remember you will need to load this new module inside the template before you call the filter)
{% load new_filter_module %}