Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

excluding url pattern from django app..is it possible?

Tags:

python

django

So I use a django app for my project. Let's say we called it otherapp

Include otherapp urls in my project urls:

url(r'^other/', include('otherapp.urls'))

but there's one url pattern in otherapp.urls that I don't want to include for some reason.
Is it possible?

like image 505
mhd Avatar asked May 05 '14 08:05

mhd


People also ask

What is the difference between path and URL in Django?

In Django 2.0, you use the path() method with path converters to capture URL parameters. path() always matches the complete path, so path('account/login/') is equivalent to url('^account/login/$') . The part in angle brackets ( <int:post_id> ) captures a URL parameter that is passed to a view.

What happens if you skip the trailing slash in Django?

If you're creting a RESTful API using Django, this can be a good solution when developers POST data directly to endpoint URL. When using APPEND_SLASH , if they accidently sent it without trailing slash, and your urlconf is WITH a trailing slash they would get an exception about data lose when redirecting POST requests.

How do I change the default URL in Django?

Set up app folder's urls.py and html files In the same directory, you should have a file named views.py. We will create a function called index which is what makes the http request for our website to be loaded. Now, we've set it up such that http://127.0.0.1:8000/homepage will render the HTML template index.

How do I pass URL parameters in Django?

Django URL pass parameter to view You can pass a URL parameter from the URL to a view using a path converter. Then “products” will be the URL endpoint. A path converter defines which type of data will a parameter store. You can compare path converters with data types.


1 Answers

There are two ways to do this:

A. Just define all urls here which you want to include. (but this is so not DRY)

OR

B. Define the url here which you want to exclude and raise 404 on it. (a little hackish): e.g.

     urlpatterns = ('',
       url('^other/url/to/exclude', django.views.defaults.page_not_found),
       url(r'^other/', include('otherapp.urls')),
     )
like image 129
Sahil kalra Avatar answered Oct 03 '22 17:10

Sahil kalra