Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

To support newer django version & enable error logging #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion backend/auth/utils.py → backend/auth2/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json
from django.http import HttpResponse
from auth.models import Token
from auth2.models import Token


def json_response(response_dict, status=200):
Expand Down
7 changes: 4 additions & 3 deletions backend/auth/views.py → backend/auth2/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@
from django.contrib.auth.models import User
from django.db import IntegrityError
from django.views.decorators.csrf import csrf_exempt
from auth.models import Token
from auth.utils import json_response, token_required
from auth2.models import Token
from auth2.utils import json_response, token_required


@csrf_exempt
def register(request):
if request.method == 'POST':
username = request.POST.get('username', None)
password = request.POST.get('password', None)

print 'hello'

if username is not None and password is not None:
try:
user = User.objects.create_user(username, None, password)
Expand Down
39 changes: 38 additions & 1 deletion backend/backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'auth',
'auth2',
)

MIDDLEWARE_CLASSES = (
Expand All @@ -52,6 +52,43 @@

WSGI_APPLICATION = 'backend.wsgi.application'

LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'formatters': {
'verbose': {
'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s',
},
'simple': {
'format': '%(levelname)s %(message)s',
},
},
'handlers': {
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
},
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'verbose',
},
},
'loggers': {
'django.request': {
# 'handlers': ['mail_admins'],
'handlers': ['console'],
'level': 'INFO', #INFO
'propagate': True,
},
}
}

# Database
# https://docs.djangoproject.com/en/1.6/ref/settings/#databases
Expand Down
6 changes: 3 additions & 3 deletions backend/backend/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
# Examples:
# url(r'^$', 'backend.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
url(r'^api/register/$', 'auth.views.register'),
url(r'^api/login/$', 'auth.views.login'),
url(r'^api/logout/$', 'auth.views.logout'),
url(r'^api/register/$', 'auth2.views.register'),
url(r'^api/login/$', 'auth2.views.login'),
url(r'^api/logout/$', 'auth2.views.logout'),
url(r'^admin/', include(admin.site.urls)),
)