register_converter

49 views
Skip to first unread message

אורי

unread,
May 6, 2020, 5:23:26 AM5/6/20
to django...@googlegroups.com
Hi,

Do I have to use register_converter in any file using it? I have a project with many urls.py files, and I want to register converters which will be used in multiple files. How do I register them? Do I have to register them in all the urls.py files? And where in my project should I put the converters definitions?

Also, can I register a converter with the name "slug"? (which is also defined by Django). I want to define "slug" as any string containing letters a-z, A-Z, digits 0-9, "-", ".", or "_" (the 2 latest characters will be redirected to "-"). for example the paths "/uri_rodberg/" and "/uri.rodberg/" will be redirected to "/uri-rodberg/". And not to use the Django-defined "slug".

I also want to define "digits" as any sequence of digits 0-9, but it's a string - not an integer. For example an ID of a user or entity. It can start with any numbers of leading zeros.

Andréas Kühne

unread,
May 6, 2020, 8:05:06 AM5/6/20
to django...@googlegroups.com
Hi,

You register your converter in the main urls.py file (which is usually in the main project name, alongside settings.py). That's all you need to do.

I don't know about the slug converter though - I would just reregister it and see what happens :)

Regards,

Andréas


‪Den ons 6 maj 2020 kl 11:23 skrev ‫אורי‬‎ <u...@speedy.net>:‬
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CABD5YeHRp7rvqrBirbSObVFOsxwfDX%2BDnKoxraoq5Wyc4Fu84g%40mail.gmail.com.

אורי

unread,
May 6, 2020, 8:38:12 AM5/6/20
to django...@googlegroups.com
Hi,

I checked and if I define a converter with a name of a default converter, such as "slug" - it overrides the default converter. The line that causes this is the line return {**DEFAULT_CONVERTERS, **REGISTERED_CONVERTERS} in get_converters() in Django.


Andréas Kühne

unread,
May 6, 2020, 9:55:59 AM5/6/20
to django...@googlegroups.com
Great - thanks also for posting the answer here as well!

Regards.

Andréas


‪Den ons 6 maj 2020 kl 14:37 skrev ‫אורי‬‎ <u...@speedy.net>:‬
Reply all
Reply to author
Forward
0 new messages