From 4767ec52139f3cd9dca66beb8ac4563e3183cd1c Mon Sep 17 00:00:00 2001 From: Ivan Nikiforov Date: Mon, 23 Apr 2018 16:50:24 +0300 Subject: [PATCH] Added debug tools --- .gitignore | 5 +++++ README.md | 19 ++++++++++++++----- otus_site/settings.py | 3 +++ otus_site/urls.py | 6 ++++++ requirements.txt | 2 ++ 5 files changed, 30 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 9e8f911..2efe513 100644 --- a/.gitignore +++ b/.gitignore @@ -102,3 +102,8 @@ ENV/ # PyCharm stuff .idea/ + +# Databases +.sqlite +.sqlite3 + diff --git a/README.md b/README.md index 4acca3d..0cedc41 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,15 @@ -# py_webapi_django_elearning_example -REST API for some MOOC platform with authentication and authorization +This example project shows REST API for some MOOC platform with authentication and authorization. -Installation and run is pretty straightforward and you can follow the same steps as for [py_webapi_django_example](https://github.com/niki4/py_webapi_django_example), however here's some differences. +## Installation and run... +... are pretty straightforward and you can just follow the same steps as for [py_webapi_django_example](https://github.com/niki4/py_webapi_django_example), however here's some differences. -* Once you've done `./manage.py migrate` command, create an admin user, which is allowed to make changes in data using REST API (in other words, Admin authorized user will be able to send POST/PUT/DELETE to endpoints): +* Once you've done `./manage.py migrate` command, create an admin user, which is allowed to make changes in data using REST API (in other words, Admin authorized user will be allowed to send POST/PUT/DELETE to endpoints): ```bash python manage.py createsuperuser ``` Now you could run the server with `./manage.py runserver` command and open Django Admin Panel with the URL http://127.0.0.1:8000/admin/ -Admins (as the user you've just created with the abovementioned command) to make changes in data using both admin panel and REST API, whilst regular users and anonymous could only view data provided by the REST API endoints. +Admins (as the one you've just created with the abovementioned command) can change data using both admin panel and REST API, whilst regular users and anonymous could only view data provided by the REST API endpoints. Those permissions are defined in `otus_site/permissions.py` and applied to endpoints in `catalog/views.py` By the way, navigating to root level in your browser (or another http client like _curl_) will return list of available endpoints: ``` @@ -25,3 +25,12 @@ Vary: Accept "webinars": "http://127.0.0.1:8000/webinars/" } ``` + +## Debug tools +The project comes with some 3rd-party debug tools connected, which helps on web-site debug and speed up development: +* [django-debug-toolbar](https://django-debug-toolbar.readthedocs.io/en/stable/panels.html) - Nice and useful panel on the right hand side of your site. Displays the background site processes when you interact with (HTTP/SQL queries, templates, urls) +* [django-extensions](https://django-extensions.readthedocs.io/) - Provides additional set of commands/tools you can run with manage.py, like `shell_plus` or `generate_secret_key`. To list all the commands check the `[django_extensions]` section when you run `./manage.py` without any options. +* [django-configurations](http://django-configurations.readthedocs.io/en/latest/) - This one makes `DJANGO_CONFIGURATION=Dev ./manage.py` command possible. + +All the debug tools are turned on by default when `DJANGO_CONFIGURATION=Dev` (that means when `DEBUG = True` + in `otus_site/settings.py`) and should be normally turned off in production environment, so bear this in mind. \ No newline at end of file diff --git a/otus_site/settings.py b/otus_site/settings.py index 0de9138..f7c4ca4 100644 --- a/otus_site/settings.py +++ b/otus_site/settings.py @@ -21,11 +21,13 @@ class Base(Configuration): 'django.contrib.staticfiles', 'rest_framework', 'django_extensions', + 'debug_toolbar', 'users.apps.UsersConfig', 'catalog.apps.CatalogConfig', ] MIDDLEWARE = [ + 'debug_toolbar.middleware.DebugToolbarMiddleware', 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', @@ -94,3 +96,4 @@ class Base(Configuration): class Dev(Base): DEBUG = True + INTERNAL_IPS = '127.0.0.1' diff --git a/otus_site/urls.py b/otus_site/urls.py index 1badf70..2f5fc2c 100644 --- a/otus_site/urls.py +++ b/otus_site/urls.py @@ -1,3 +1,4 @@ +from django.conf import settings from django.conf.urls import include from django.contrib import admin from django.urls import path @@ -6,3 +7,8 @@ path('admin/', admin.site.urls), path('', include('catalog.urls')), ] + +if settings.DEBUG: + import debug_toolbar + urlpatterns = [ + path(r'__debug__/', include(debug_toolbar.urls)),] + urlpatterns diff --git a/requirements.txt b/requirements.txt index e0498b7..d89a94c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,5 @@ Django==2.0.4 django-configurations==2.0 +django-debug-toolbar==1.9.1 +django-extensions==2.0.7 django-rest-framework==0.1.0