Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplified routing syntax #27

Closed
wants to merge 7 commits into from

Conversation

sjoerdjob
Copy link
Contributor


urlpatterns = [
path('/users/', views.user_list),
path('/users/<id>/', views.user_detail),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous example left off the leading slash, but this one has it. I suspect that we want the former, but which is correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I just copied & pasted that from the original proposal from Tom Christie, but other parts of the DEP are clear that it is about path components and not URLs, so this will have to change.

The route argument to the ``path`` function signifies a component of the
full URL, and as such should (normally) not start with a ``/``.

Thanks Ryan Hiebert.

* Enforce that new style ``path()`` arguments must not start with a leading
``'^'``.
* Enfore that old style ``url()`` arguments must start with a leading ``'^'``.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: "Enforce".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I fixed it and pushed a new commit.

@wlonk
Copy link

wlonk commented Oct 19, 2016

I love this proposal, for the record. It obviates a tiny library I made for myself, in a great way.

Thanks Kit La Touche!
@tomchristie
Copy link
Member

Okay, I think this is ready for a formal DEP #, right?
Some minor stuff around the edges to be worked out as we progress.

Copy link
Contributor

@alexwlchan alexwlchan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I flagged a few minor spelling errors, but otherwise looks good! Django's URL routing is a point of personal frustration (I came from Flask to Django), so I'd be very pleased if this got fixed. 😄


There are two aspects to this that we'd like to improve on:

* The Regex based URL syntax is unneccessarily verbose and complex for the vast
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/s/unneccessarily/unnecessarily

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the spelling reports! I've just fixed them.


We might also consider including `a regex converter <http://stackoverflow.com/questions/5870188/does-flask-support-regular-expressions-in-its-url-routing>`_.

Furthermore, an interface for implementating custom converters should exist. We
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/s/implementating/implementing

* The items in the ``converters`` argument would each be instances of
``BaseConverter``

(An alternate might be to add separate ``converter_args`` and
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/s/alternate/alternative

Preventing unintended errors
----------------------------

*The following behaviour is not neccessary, and we might not choose to add
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/s/neccessary/necessary

Implementation tasks
====================

The following independant tasks can be identified:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/s/independant/independent

@sjoerdjob
Copy link
Contributor Author

@tomchristie: Now that I've fixed the spelling issues, I think it is ready for a formal DEP #.

@mjtamlyn
Copy link
Member

I've had a skim through and I feel this is ready to be merged into the drafts folder. @tomchristie - you should have the commit access to do that?

@tomchristie
Copy link
Member

@mjtamlyn - Nope, I don't have commit access. Yup, agree that it's ready for drafts.

@mjtamlyn
Copy link
Member

Assigned number 0201 (seemed unlikely it would get done by 1.11 feature freeze in January) and I couldn't work out how to fit 1.11 into the number scheme anyway. Merged into master in 5b306de

@mjtamlyn mjtamlyn closed this Nov 11, 2016
@tomchristie
Copy link
Member

Assigned number 0201

Does that have any impact, or is it just symbolic? I'd like to aim to get it in for 1.11 and can make some time to help with that if needed.

@mjtamlyn
Copy link
Member

mjtamlyn commented Nov 11, 2016

It's pretty much symbolic the number yeah. If you can get it all working and merged by the feature freeze then great, but it's still just a draft. We'll need a concrete plan and a technical board vote to get it to accepted, and then a mergable patch to get it to final.

@tomchristie
Copy link
Member

tomchristie commented Nov 11, 2016

The current state of the pull request is pretty far along django/django#7482

The "Parametrisable converter syntax" is the one substantial technical aspect of this that's still TODO. (Plenty to do in the documentation and a couple of more minor dev aspects to address)

Putting that aside I don't see any reason for us not to starting to addressing the potential blockers for this getting in, namely:

  • Do we adopt path throughout the documentation at this point or not? (We could add it as an option, but not use it as the canonical choice to start with if we wanted.)
  • Are we happy with from django.urls import path and from django.urls import regex_path or not? (We could stick with django.conf.urls if we wanted.)
  • Do we put django.conf.urls import url onto a deprecation timeline or not? (It's used in 100% of projects right now, should we could choose to extend its usage as a deprecation-free synonym of regex_path)

@sjoerdjob
Copy link
Contributor Author

If it helps, I would not mind shelving the parametrisation, making it more likely that this can be completed before the deadline. (Also, I think it is a bit more controversial and a bit less specified than the rest of the proposal, to be honest).

@jezdez
Copy link
Contributor

jezdez commented Nov 11, 2016

@tomchristie

  1. yes, adopt it throughout the docs
  2. django.urls is the canonical place for URL stuff, also move django.core.urlresolvers into django.urls.resolvers
  3. yes, django.conf.urls.url needs to be deprecated as usual

@mjtamlyn
Copy link
Member

  1. Yes to docs
  2. +1 to flattening the import paths
  3. Probably.

I'm concerned about the lack of technical details regarding reversing of these new URLs in the DEP. I see from the PR that some of this has been solved? The approaches should be mentioned here.

I'd also like to see how the direction of any internal reworking here can be combined with Andrew's routing taking other attributes in channels and with django-hosts. I'm happy for the conclusion to be that this could be a future piece of work, but I'd like to see it discussed within the DEP.

@sjoerdjob
Copy link
Contributor Author

I agree with respect to docs and the flattened import paths.

For deprecation, I think the patterns gives a good example: it was deprecated in 1.8 and removed in 1.10. I think if we can get this in before 1.11, maybe we could even remove the old import location for 2.0.

The part regarding reversing has not been mentioned in the DEP indeed, but are a solvable problem. I'll create a PR updating DEP0201 to document the changes needed the reversing (API and internals).

As for the Channels and Django-Hosts: Sounds interesting, but I think for now it needs to be "future work" as

  1. I don't see a hook to add this and allow reversing to still work.
  2. It's orthogonal: this is only about simplified syntax (and converting data-types). channels/hosts is about matching on different data-types.

Again, I'll see if I can reword this a bit more elegantly for in DEP0201.

@tomchristie
Copy link
Member

Docs patch, in progress: django/django#7542

@sjoerdjob
Copy link
Contributor Author

I created a PR with some amendments: #34

@sjoerdjob sjoerdjob deleted the simplified-routing-syntax branch November 14, 2016 08:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants