from django.conf.urls import simple_url
from . import views
urlpatterns = [
simple_url('articles/2003/', views.special_case_2003),
simple_url('articles/:year)/', views.year_archive),
simple_url('articles/:year/:month/', views.month_archive),
simple_url('articles/:year/:month/:day/', views.article_detail),
]
All parameters would be passed to the view as keyword parameters with the name given and as a string, and validation would happen there instead.
I'm thinking there should be no settings with simple_url, and that any more advanced use-case should switch to using url instead.
Two questions:
A) What do you think about the prospect of simplifying urls.py for beginners?
B) What do you think about the specific suggestion to mimic Rails urls with a simple_url tag?
Thanks for reading!
--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscribe@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/3d002c25-9d98-49b1-b84c-55bc39c6a0f9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CAK52boUa_D-%2BVaf6VPgrA0YDAK4CWFbjFSWxV3RiVf-JEDXm1Q%40mail.gmail.com.
This is actually an interesting concept, and wouldn't incur an overheard at runtime if simple_url translated in to full regex format at launch time (or on first request, which is when the urls get loaded if I recall correctly).
I don't think this would get in the way of includes, and if it's a translator to full regex format, it can be done in a separate format.
The example from flask is interesting. What if we could define regex for our urls to have it pluggable.
simple_url.register('integer', r'[0-9]+')
This is actually an interesting concept, and wouldn't incur an, overheard at runtime if simple_url translated in to full regex format at launch time (or on first request, which is when the urls get loaded if I recall correctly).
I don't think this would get in the way of includes, and if it's a translator to full regex format, it can be done in a separate format.
Your example of flask's is interesting. What if we could define regex for our urls to have it pluggable.
simple_url.register('integer', r'[0-9]+')
On 13 Sep 2016 07:26, "Ares Ou" <are...@gmail.com> wrote:
Hi,Actually flask uses a style very similar to what you want.To my knowing, you must use this pattern for Django because it has the concept of includingURLs.Routing in flask:@app.route('post/<integer:post_id>', methods=['GET'])def post_view(post_id=None):# do something to render the postreturn render_template('post.html', post=post)But the problem is, you have to specify the whole URL for every view you define.Django avoids this by separating URL patterns into different levels, that's why it uses regex toidentify the exact path. I guess it is hard for Django to organize URLs in different apps by usingsuch simple method.Looking forward to more ideas!
Best regards,Ares OuSoftware Engineer / Full-Stack Python Developer | Phone: (510) 328 - 5968Blog: http://aresou.net | Github: https://github.com/aresowj | Stack Overflow: http://stackoverflow.com/users/5183727/ares-ouAres Ou
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CAFCGC%3DaX-0fvW9K%3D6dZa_wMAQVDLUAKc6mKoSzaOfCObhbmViw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscribe@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CALs0z1Zzz5YYb6OUoBxj0ShbmeHfwpiDe5ZK-A-k7XW2wA_uew%40mail.gmail.com.
> email to django-developers+unsubscribe@googlegroups.com.
> To post to this group, send email to django-developers@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-developers.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-developers/37e44d86-696d-4b36-803a-0089232eedf9%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.
--
Cordialement, Coues Ludovic
+336 148 743 42
--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscribe@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CAEuG%2BTa-d_RsMqj5HbspEBdKUKemfBPvjBh2%2BdJmQjU04b-V7w%40mail.gmail.com.
and more experienced users are expected to switch over to using regexes directly to get the exact behavior they want.
Beginners likely won't look at all the different options and choose one based on it's merits, they'll pick whatever their teacher suggests they use. Also installing an extra package when setting up django feels a bit strange.
> email to django-develop...@googlegroups.com.
> To post to this group, send email to django-d...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-developers.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-developers/37e44d86-696d-4b36-803a-0089232eedf9%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.
--
Cordialement, Coues Ludovic
+336 148 743 42
--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
There is third party module providing third party url function. Surlex
[1] have been mentionned. But any third party solution will need to
provide function compatible with django.conf.urls.url.
Line 64 of django/urls/revolvers.py is get_resolver. This function
return a RegexURLResolver, using is argument or the setting
ROOT_URLCONF as argument.
This make impossible, for exemple, to have resolver giving to the view
an int argument.
[1] http://codysoyland.com/2009/sep/6/introduction-surlex/
In my opinion, it should remain a string. That's the behaviour it is now, and it'll mean it can remain as a 3rd party package.
Perhaps to show it isn't being cast, it could be renamed to "integer", which would avoid confusion
--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscribe@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/d11376c9-8a6f-45bd-940d-bc72589bf8e4%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
Tim Graham: Does this change your view that this should be done outside of core? Do you buy the argument that beginners are unlikely to install third party packages when learning django?
As cool as this idea sounds, I really don't think the URL dispatcher
is a correct component to make database queries. FWIW, I've seen
similar magic implemented in view decorators, and the thing I remember
the most from this experience was that it made it a lot harder to
follow what was happening where.
Moreover, I can imagine this turning into a complicated mess of a
syntax to allow query customizations using a weird DSL really quickly.
After all, if we allow PK lookups, it's not that unreasonable to also
want to be able to lookup by other keys, and it all goes downhill from
here.
Cheers,
Michal