Skip to content

Commit

Permalink
Added debug tools
Browse files Browse the repository at this point in the history
  • Loading branch information
niki4 committed Apr 23, 2018
1 parent 881eba6 commit 4767ec5
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,8 @@ ENV/

# PyCharm stuff
.idea/

# Databases
.sqlite
.sqlite3

19 changes: 14 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -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:
```
Expand All @@ -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.
3 changes: 3 additions & 0 deletions otus_site/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -94,3 +96,4 @@ class Base(Configuration):

class Dev(Base):
DEBUG = True
INTERNAL_IPS = '127.0.0.1'
6 changes: 6 additions & 0 deletions otus_site/urls.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 4767ec5

Please sign in to comment.