Skip to content

Django Tool

Testing URLs:

You can test URLs using Django's test client to see how your views respond to different requests. For example:

Example

>>> from django.test import Client
>>> client = Client()
>>> response = client.get('/myapp/myurl/')
>>> print(response.status_code)
Note

In your settings.py, locate the ALLOWED_HOSTS setting and add 'testserver' to the list. If you're using the wildcard '*', make sure 'testserver' is included there.

# settings.py

ALLOWED_HOSTS = ['yourdomain.com', 'testserver']

By adding 'testserver' to the ALLOWED_HOSTS setting, Django will allow requests with the HTTP_HOST header set to 'testserver' during testing.


Using Django Extensions:

Install and utilize Django Extensions, a package that adds various useful functionalities to Django, including shell_plus, which loads all models into the shell namespace to make interacting with them easier.

bash
$ pip install django-extensions
$ python manage.py shell_plus

To enable django_extensions in your project you need to add it to INSTALLED_APPS in your projects settings.py file:

INSTALLED_APPS = (
    ...
    'django_extensions',
    ...
)

Django Debug Toolbar:

Install and use Django Debug Toolbar to analyze and optimize your application during development.

bash
$ pip install django-debug-toolbar

Then, add it to your INSTALLED_APPS and configure it properly in your settings file.

INSTALLED_APPS = [
    # ...
    "debug_toolbar",
    # ...
]

Reference