All Projects → venturachrisdev → Djurl

venturachrisdev / Djurl

Licence: other
Simple yet helpful library for writing Django urls by an easy, short and intuitive way.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Djurl

Django Multiurl
Have you ever wanted multiple views to match to the same URL? Now you can.
Stars: ✭ 268 (+215.29%)
Mutual labels:  django, routing, url
node-match-path
Matches a URL against a path. Parameters, wildcards, RegExp.
Stars: ✭ 30 (-64.71%)
Mutual labels:  url, routing
parse-github-url
Parse a Github URL into an object. Supports a wide variety of GitHub URL formats.
Stars: ✭ 114 (+34.12%)
Mutual labels:  url, regex
url
Build and parse URLs. Useful for HTTP and "routing" in single-page apps (SPAs)
Stars: ✭ 69 (-18.82%)
Mutual labels:  url, routing
Url Parser
Parse URLs into nicely structured data
Stars: ✭ 118 (+38.82%)
Mutual labels:  routing, url
Js Tokens
Tiny JavaScript tokenizer.
Stars: ✭ 166 (+95.29%)
Mutual labels:  tokenizer, regex
url-trailing-slash
Allows enforcing URL routes with or without trailing slash
Stars: ✭ 35 (-58.82%)
Mutual labels:  url, routing
Django Macros Url
Django Macros URL. Routing must be simple as possible
Stars: ✭ 121 (+42.35%)
Mutual labels:  django, routing
Url Regex
Regular expression for matching URLs
Stars: ✭ 286 (+236.47%)
Mutual labels:  url, regex
Ffrouter
Powerful and easy-to-use URL routing library in iOS that supports URL Rewrite(强大、易用、支持 URL Rewrite的 iOS 路由库)
Stars: ✭ 263 (+209.41%)
Mutual labels:  routing, url
url-regex-safe
Regular expression matching for URL's. Maintained, safe, and browser-friendly version of url-regex. Resolves CVE-2020-7661 for Node.js servers.
Stars: ✭ 59 (-30.59%)
Mutual labels:  url, regex
React Easy Params
🔗 Auto synchronize your state with the URL and LocalStorage.
Stars: ✭ 73 (-14.12%)
Mutual labels:  routing, url
golgi
A composable routing library for Haxe.
Stars: ✭ 37 (-56.47%)
Mutual labels:  url, routing
Bidi
Bidirectional URI routing
Stars: ✭ 941 (+1007.06%)
Mutual labels:  routing, url
Lit Element Router
A LitElement Router (1278 bytes gzip)
Stars: ✭ 85 (+0%)
Mutual labels:  routing, regex
Drf Autodocs
Ultimately automated DRF documentation rendering(UNMAINTAINED)
Stars: ✭ 82 (-3.53%)
Mutual labels:  django
Drf Datatable Example Server Side
DataTables Example (server-side) - Python Django REST framework
Stars: ✭ 84 (-1.18%)
Mutual labels:  django
Sentence Splitter
Text to sentence splitter using heuristic algorithm by Philipp Koehn and Josh Schroeder.
Stars: ✭ 82 (-3.53%)
Mutual labels:  tokenizer
Archer
基于inception的自动化SQL操作平台,支持SQL执行、LDAP认证、发邮件、OSC、SQL查询、SQL优化建议、权限管理等功能,支持docker镜像
Stars: ✭ 1,239 (+1357.65%)
Mutual labels:  django
Mezzanine Api
RESTful web API for Mezzanine CMS
Stars: ✭ 84 (-1.18%)
Mutual labels:  django

DjUrl - Django urls Build Status

Simple yet helpful library for writing Django urls by an easy, short and intuitive way.

Why should I use DjUrl?

Django routing urls aren't easy to deal with, regular expressions can become a nightmare sometimes. Just imagine dealing with such routes in your django app:

from django.conf.urls import url
from core import BlogView, SinglePostView, SearchResultsView, ArchiveView

urlpatterns = [
	# => /blog/
	url(r'^blog/$', BlogView.as_view(), name="blog"),
	# => /blog/5
	url(r'^blog/(?P<post_id>[0-9]+)/$', SinglePostView.as_view(), name="singlepost"),
	# => /blog/search/sometitle
	url(r'^blog/search/(?P<search_query>[A-Za-z0-9_-]+)/$', SearchResultsView.as_view(), name="search"),
	# => /blog/archive/2017/02/12
	url(r'^blog/archive/(?P<date>[0-9]{4}-(0?([1-9])|10|11|12)-((0|1|2)?([1-9])|[1-3]0|31))/$',
		ArchiveView.as_view(), name="archive")
]

That's too much work and you lost me in those regex. With DjUrl this comes easy, you just need to express what you want, DjUrl will handle the regular expressions for you:

from djurl import url
from core import BlogView, SinglePostView, SearchResultsView, ArchiveView

urlpatterns = [
	url('/blog', BlogView, name="blog"),
	url('/blog/:id', SinglePostView, name="singlepost"),
	url('/blog/search/:query', SearchResultsView, name="search"),
	url('/blog/archive/:date', ArchiveView, name="archive")
]

No regex, just clean paths and param names. You can now pass the regex work to DjUrl and concentrate in the bussiness logic. It saves you a lot of time and code. You don't need to worry about the routes anymore. Note you don't need to call as_view in your CBV's. DjUrl does this for you as well.

Usage

Now you know what you should use DjUrl, It's time to learn how to use it. DjUrl has a list of known/default pattern that you can use in your routes, these are:

  • id: A secuence of characters from 0 to 9. Ej: 1, 12, 454545, 8885500, 8
  • pk: A primary key, it's like id but needed for Class Based Views.
  • page: falls in the same category, but you'd use page for a better param name.
  • slug: A simple string (alphanumeric characters).
  • query: A search parameter. It allows some special characters that slug doesn't. Ex: hello%20word, don%27t_quote-me
  • day: A number between 01,..., 31.
  • month: A number between 01,...,12.
  • year: A four digits number: 1998, 2017, 2018, 3015, 2020, 1406...
  • date: An expression with year-month-day format: 2017-06-23, 1998-10-20, 1492-10-12
  • filename: An expression with *.\w{2,4} format: index.js, detail.html, 'my_book.pdf', 'dfj358h-g9854-fn84n4.tmp'
  • UUID: Universally unique identifier is a 128-bit number used to identify information in computer systems. Use a format as xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx. Ex: 123e4567-e89b-12d3-a456-426655440000

That means, wherever you put /:id you can use it in your view as param (named id).

url('post/:pk/comment/:id', myview, name="post_comment")

Your view:

def myview(request, pk, id):
	# Use `pk` (post's) and `id` (comment's)

But what if I have two or more id's, or two slugs? What if I wanted to use a custom name for my id's? - Ok, you can use custom names if you end it with _ + the pattern type. - What?...

url('post/:post_pk/comment/:comment_id', myview, ...)
# ...
def myview(request, post_pk, comment_id):
	# `post_pk` is parsed as a :pk and `comment_id` like an :id

Yeah, it sounds good!, but... What if I wanted to use my own patterns? - Easy, any world in the path is of type :slug by default, but if you need a custom pattern you can register many as you want:

from djurl import url, register_pattern
register_pattern('hash', '[a-f0-9]{9}')
# parsed as slug
url('/:user', myUserView),
# custom pattern
url('/:hash', myview),

If you have questions, visit our FAQ's or open an issue.

Install

If you want to have fun with this library and integrate it to your project, just type in your terminal:

$ pip install djurl

or, clone the repo and type:

$ python setup.py install

Enjoy it!

Testing

Clone the repo and run Djurl tests by:

$ python setup.py test

Contributions

If you've found a bug/error or just have questions, feel free to open an issue. And, Pull requests are welcome as well. Don't forget to add your name to CONTRIBUTORS.md

License

Copyright 2017 Christopher Ventura

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].