Since spaces are illegal in URLs,
http:
unacceptably. The urlencode filter will simply replace the space with% 20, which is ugly / inelegant even if it does a certain job. A much better solution is to use the "slug" field in your model, which is a cleaned version of the header field (I assume this is called the header field). You want to get a clean URL, for example:
http:
To make this happen, use something like this in your model:
class Player(models.Model): title = models.CharField(max_length=60) slug = models.SlugField() ...
If you want the slug field to be pre-populated by the administrator, use something like this in admin.py:
class PlayerAdmin(admin.ModelAdmin): prepopulated_fields = {"slug": ("title",)} .... admin.site.register(Player,PlayerAdmin)
Now when you enter the new Player in admin, if you type “Hockey Player” for Title, the Slug field will automatically become “hockey_player”.
In the template you should use:
{% for item in field_list %} <a href={% url index_view %}{{ item.slug }}/> {{ item }} </a> <br> {% endfor %}
source share