Last active
July 28, 2020 19:06
-
-
Save alisonamerico/3efbdc6103610d1134c24583ecb99451 to your computer and use it in GitHub Desktop.
loginfacebook
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# urls.py | |
from django.contrib import admin | |
from django.urls import include, path | |
from rest_framework.authtoken.views import obtain_auth_token | |
from touristspots.api.views import FacebookLogin | |
urlpatterns = [ | |
path('admin/', admin.site.urls), | |
path('', include('touristspots.base.urls')), | |
# Token auth | |
path('api/v1/auth/api-token-auth/', obtain_auth_token, name='api-token-auth'), | |
# The rest of the endpoints | |
path('api/v1/', include('touristspots.api.urls'), name='api-root'), | |
# Social Authentication | |
path('dj-rest-auth/', include('dj_rest_auth.urls')), | |
path('dj-rest-auth/registration/', include('dj_rest_auth.registration.urls')), | |
path('dj-rest-auth/facebook/', FacebookLogin.as_view(), name='fb_login') | |
] | |
============================================================================================= | |
# views.py | |
from allauth.socialaccount.providers.facebook.views import FacebookOAuth2Adapter | |
from dj_rest_auth.registration.views import SocialLoginView | |
from rest_framework import viewsets | |
from rest_framework.permissions import IsAuthenticated | |
from rest_framework import filters | |
from touristspots.api.models import Favorite, TouristSpot | |
from touristspots.api.serializers import TouristSpotSerializer, FavoriteSerializer | |
from django.contrib.gis.measure import Distance | |
from django.contrib.gis.geos import Point | |
class TouristSpotViewSet(viewsets.ModelViewSet): | |
""" | |
TouristSpotViewSet: | |
- Performs queries of objects in the database; | |
- Implements search fields and sort filters; | |
- Authentication and permission for API access. | |
""" | |
queryset = TouristSpot.objects.all() | |
serializer_class = TouristSpotSerializer | |
permission_classes = (IsAuthenticated,) | |
filter_backends = [filters.SearchFilter] | |
search_fields = ['name'] | |
lat = 52.5 | |
lng = 1.0 | |
radius = 5 | |
point = Point(lng, lat) | |
clients_within_radius = queryset.filter( | |
geographical_location__distance_lt=( | |
point, Distance(km=radius) | |
) | |
) | |
class FavoriteViewSet(viewsets.ModelViewSet): | |
""" | |
FavoriteViewSet: | |
- Performs queries of objects in the database; | |
- Implements search fields and sort filters; | |
- Authentication and permission for API access. | |
""" | |
queryset = Favorite.objects.all() | |
serializer_class = FavoriteSerializer | |
permission_classes = (IsAuthenticated,) | |
class FacebookLogin(SocialLoginView): | |
adapter_class = FacebookOAuth2Adapter | |
=================================================================================== | |
# settings.py | |
INSTALLED_APPS = [ | |
'django.contrib.admin', | |
'django.contrib.auth', | |
'django.contrib.contenttypes', | |
'django.contrib.sessions', | |
'django.contrib.messages', | |
'django.contrib.staticfiles', | |
'django.contrib.gis', | |
'touristspots.base', | |
'touristspots.api', | |
'rest_framework', | |
'rest_framework_gis', | |
'rest_framework.authtoken', | |
'corsheaders', | |
'django_filters', | |
'django.contrib.sites', | |
'allauth', | |
'allauth.account', | |
'allauth.socialaccount', | |
'dj_rest_auth.registration', | |
'dj_rest_auth', | |
] | |
SITE_ID = 1 | |
==================================================================================== | |
# erro | |
❯ docker-compose up | |
Starting touristspots_database ... done | |
Recreating snowman_web_1 ... done | |
Attaching to touristspots_database, snowman_web_1 | |
touristspots_database | | |
touristspots_database | PostgreSQL Database directory appears to contain a database; Skipping initialization | |
touristspots_database | | |
touristspots_database | 2020-07-28 18:28:49.514 UTC [1] LOG: starting PostgreSQL 12.3 (Debian 12.3-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit | |
touristspots_database | 2020-07-28 18:28:49.525 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432 | |
touristspots_database | 2020-07-28 18:28:49.525 UTC [1] LOG: listening on IPv6 address "::", port 5432 | |
touristspots_database | 2020-07-28 18:28:49.723 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432" | |
touristspots_database | 2020-07-28 18:28:50.589 UTC [25] LOG: database system was interrupted; last known up at 2020-07-28 16:45:37 UTC | |
touristspots_database | 2020-07-28 18:28:51.599 UTC [25] LOG: database system was not properly shut down; automatic recovery in progress | |
touristspots_database | 2020-07-28 18:28:51.643 UTC [25] LOG: redo starts at 0/3E345AA8 | |
touristspots_database | 2020-07-28 18:28:51.643 UTC [25] LOG: invalid record length at 0/3E345B90: wanted 24, got 0 | |
touristspots_database | 2020-07-28 18:28:51.643 UTC [25] LOG: redo done at 0/3E345B58 | |
touristspots_database | 2020-07-28 18:28:52.039 UTC [1] LOG: database system is ready to accept connections | |
web_1 | Operations to perform: | |
web_1 | Apply all migrations: admin, api, auth, authtoken, base, contenttypes, sessions | |
web_1 | Running migrations: | |
web_1 | No migrations to apply. | |
web_1 | Your models have changes that are not yet reflected in a migration, and so won't be applied. | |
web_1 | Run 'manage.py makemigrations' to make new migrations, and then re-run 'manage.py migrate' to apply them. | |
web_1 | Watching for file changes with StatReloader | |
web_1 | Performing system checks... | |
web_1 | | |
web_1 | System check identified no issues (0 silenced). | |
web_1 | July 28, 2020 - 18:29:16 | |
web_1 | Django version 3.0.8, using settings 'touristspots.settings' | |
web_1 | Starting development server at http://0.0.0.0:8000/ | |
web_1 | Quit the server with CONTROL-C. | |
web_1 | /code/touristspots/settings.py changed, reloading. | |
web_1 | Watching for file changes with StatReloader | |
web_1 | Performing system checks... | |
web_1 | | |
web_1 | System check identified no issues (0 silenced). | |
web_1 | | |
web_1 | You have 7 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): account, sites, socialaccount. | |
web_1 | Run 'python manage.py migrate' to apply them. | |
web_1 | July 28, 2020 - 18:33:54 | |
web_1 | Django version 3.0.8, using settings 'touristspots.settings' | |
web_1 | Starting development server at http://0.0.0.0:8000/ | |
web_1 | Quit the server with CONTROL-C. | |
web_1 | /code/touristspots/settings.py changed, reloading. | |
web_1 | Watching for file changes with StatReloader | |
web_1 | Performing system checks... | |
web_1 | | |
web_1 | System check identified no issues (0 silenced). | |
web_1 | | |
web_1 | You have 7 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): account, sites, socialaccount. | |
web_1 | Run 'python manage.py migrate' to apply them. | |
web_1 | July 28, 2020 - 18:34:08 | |
web_1 | Django version 3.0.8, using settings 'touristspots.settings' | |
web_1 | Starting development server at http://0.0.0.0:8000/ | |
web_1 | Quit the server with CONTROL-C. | |
web_1 | /code/touristspots/urls.py changed, reloading. | |
web_1 | Watching for file changes with StatReloader | |
web_1 | Performing system checks... | |
web_1 | | |
web_1 | Exception in thread django-main-thread: | |
web_1 | Traceback (most recent call last): | |
web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/models/options.py", line 581, in get_field | |
web_1 | return self.fields_map[field_name] | |
web_1 | KeyError: 'username' | |
web_1 | | |
web_1 | During handling of the above exception, another exception occurred: | |
web_1 | | |
web_1 | Traceback (most recent call last): | |
web_1 | File "/usr/local/lib/python3.8/threading.py", line 932, in _bootstrap_inner | |
web_1 | self.run() | |
web_1 | File "/usr/local/lib/python3.8/threading.py", line 870, in run | |
web_1 | self._target(*self._args, **self._kwargs) | |
web_1 | File "/usr/local/lib/python3.8/site-packages/django/utils/autoreload.py", line 53, in wrapper | |
web_1 | fn(*args, **kwargs) | |
web_1 | File "/usr/local/lib/python3.8/site-packages/django/core/management/commands/runserver.py", line 117, in inner_run | |
web_1 | self.check(display_num_errors=True) | |
web_1 | File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 392, in check | |
web_1 | all_issues = self._run_checks( | |
web_1 | File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 382, in _run_checks | |
web_1 | return checks.run_checks(**kwargs) | |
web_1 | File "/usr/local/lib/python3.8/site-packages/django/core/checks/registry.py", line 72, in run_checks | |
web_1 | new_errors = check(app_configs=app_configs) | |
web_1 | File "/usr/local/lib/python3.8/site-packages/django/core/checks/urls.py", line 40, in check_url_namespaces_unique | |
web_1 | all_namespaces = _load_all_namespaces(resolver) | |
web_1 | File "/usr/local/lib/python3.8/site-packages/django/core/checks/urls.py", line 57, in _load_all_namespaces | |
web_1 | url_patterns = getattr(resolver, 'url_patterns', []) | |
web_1 | File "/usr/local/lib/python3.8/site-packages/django/utils/functional.py", line 48, in __get__ | |
web_1 | res = instance.__dict__[self.name] = self.func(instance) | |
web_1 | File "/usr/local/lib/python3.8/site-packages/django/urls/resolvers.py", line 588, in url_patterns | |
web_1 | patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module) | |
web_1 | File "/usr/local/lib/python3.8/site-packages/django/utils/functional.py", line 48, in __get__ | |
web_1 | res = instance.__dict__[self.name] = self.func(instance) | |
web_1 | File "/usr/local/lib/python3.8/site-packages/django/urls/resolvers.py", line 581, in urlconf_module | |
web_1 | return import_module(self.urlconf_name) | |
web_1 | File "/usr/local/lib/python3.8/importlib/__init__.py", line 127, in import_module | |
web_1 | return _bootstrap._gcd_import(name[level:], package, level) | |
web_1 | File "<frozen importlib._bootstrap>", line 1014, in _gcd_import | |
web_1 | File "<frozen importlib._bootstrap>", line 991, in _find_and_load | |
web_1 | File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked | |
web_1 | File "<frozen importlib._bootstrap>", line 671, in _load_unlocked | |
web_1 | File "<frozen importlib._bootstrap_external>", line 783, in exec_module | |
web_1 | File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed | |
web_1 | File "/code/touristspots/urls.py", line 30, in <module> | |
web_1 | path('dj-rest-auth/registration/', include('dj_rest_auth.registration.urls')) | |
web_1 | File "/usr/local/lib/python3.8/site-packages/django/urls/conf.py", line 34, in include | |
web_1 | urlconf_module = import_module(urlconf_module) | |
web_1 | File "/usr/local/lib/python3.8/importlib/__init__.py", line 127, in import_module | |
web_1 | return _bootstrap._gcd_import(name[level:], package, level) | |
web_1 | File "<frozen importlib._bootstrap>", line 1014, in _gcd_import | |
web_1 | File "<frozen importlib._bootstrap>", line 991, in _find_and_load | |
web_1 | File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked | |
web_1 | File "<frozen importlib._bootstrap>", line 671, in _load_unlocked | |
web_1 | File "<frozen importlib._bootstrap_external>", line 783, in exec_module | |
web_1 | File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed | |
web_1 | File "/usr/local/lib/python3.8/site-packages/dj_rest_auth/registration/urls.py", line 4, in <module> | |
web_1 | from .views import RegisterView, VerifyEmailView | |
web_1 | File "/usr/local/lib/python3.8/site-packages/dj_rest_auth/registration/views.py", line 11, in <module> | |
web_1 | from dj_rest_auth.registration.serializers import (SocialAccountSerializer, | |
web_1 | File "/usr/local/lib/python3.8/site-packages/dj_rest_auth/registration/serializers.py", line 171, in <module> | |
web_1 | class RegisterSerializer(serializers.Serializer): | |
web_1 | File "/usr/local/lib/python3.8/site-packages/dj_rest_auth/registration/serializers.py", line 173, in RegisterSerializer | |
web_1 | max_length=get_username_max_length(), | |
web_1 | File "/usr/local/lib/python3.8/site-packages/allauth/utils.py", line 69, in get_username_max_length | |
web_1 | max_length = User._meta.get_field(USER_MODEL_USERNAME_FIELD).max_length | |
web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/models/options.py", line 583, in get_field | |
web_1 | raise FieldDoesNotExist("%s has no field named '%s'" % (self.object_name, field_name)) | |
web_1 | django.core.exceptions.FieldDoesNotExist: User has no field named 'username' | |
web_1 | /code/touristspots/api/views.py changed, reloading. | |
web_1 | Watching for file changes with StatReloader | |
web_1 | Performing system checks... | |
web_1 | | |
web_1 | Exception in thread django-main-thread: | |
web_1 | Traceback (most recent call last): | |
web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/models/options.py", line 581, in get_field | |
web_1 | return self.fields_map[field_name] | |
web_1 | KeyError: 'username' | |
web_1 | | |
web_1 | During handling of the above exception, another exception occurred: | |
web_1 | | |
web_1 | Traceback (most recent call last): | |
web_1 | File "/usr/local/lib/python3.8/threading.py", line 932, in _bootstrap_inner | |
web_1 | self.run() | |
web_1 | File "/usr/local/lib/python3.8/threading.py", line 870, in run | |
web_1 | self._target(*self._args, **self._kwargs) | |
web_1 | File "/usr/local/lib/python3.8/site-packages/django/utils/autoreload.py", line 53, in wrapper | |
web_1 | fn(*args, **kwargs) | |
web_1 | File "/usr/local/lib/python3.8/site-packages/django/core/management/commands/runserver.py", line 117, in inner_run | |
web_1 | self.check(display_num_errors=True) | |
web_1 | File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 392, in check | |
web_1 | all_issues = self._run_checks( | |
web_1 | File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 382, in _run_checks | |
web_1 | return checks.run_checks(**kwargs) | |
web_1 | File "/usr/local/lib/python3.8/site-packages/django/core/checks/registry.py", line 72, in run_checks | |
web_1 | new_errors = check(app_configs=app_configs) | |
web_1 | File "/usr/local/lib/python3.8/site-packages/django/core/checks/urls.py", line 40, in check_url_namespaces_unique | |
web_1 | all_namespaces = _load_all_namespaces(resolver) | |
web_1 | File "/usr/local/lib/python3.8/site-packages/django/core/checks/urls.py", line 57, in _load_all_namespaces | |
web_1 | url_patterns = getattr(resolver, 'url_patterns', []) | |
web_1 | File "/usr/local/lib/python3.8/site-packages/django/utils/functional.py", line 48, in __get__ | |
web_1 | res = instance.__dict__[self.name] = self.func(instance) | |
web_1 | File "/usr/local/lib/python3.8/site-packages/django/urls/resolvers.py", line 588, in url_patterns | |
web_1 | patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module) | |
web_1 | File "/usr/local/lib/python3.8/site-packages/django/utils/functional.py", line 48, in __get__ | |
web_1 | res = instance.__dict__[self.name] = self.func(instance) | |
web_1 | File "/usr/local/lib/python3.8/site-packages/django/urls/resolvers.py", line 581, in urlconf_module | |
web_1 | return import_module(self.urlconf_name) | |
web_1 | File "/usr/local/lib/python3.8/importlib/__init__.py", line 127, in import_module | |
web_1 | return _bootstrap._gcd_import(name[level:], package, level) | |
web_1 | File "<frozen importlib._bootstrap>", line 1014, in _gcd_import | |
web_1 | File "<frozen importlib._bootstrap>", line 991, in _find_and_load | |
web_1 | File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked | |
web_1 | File "<frozen importlib._bootstrap>", line 671, in _load_unlocked | |
web_1 | File "<frozen importlib._bootstrap_external>", line 783, in exec_module | |
web_1 | File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed | |
web_1 | File "/code/touristspots/urls.py", line 27, in <module> | |
web_1 | path('api/v1/', include('touristspots.api.urls'), name='api-root'), | |
web_1 | File "/usr/local/lib/python3.8/site-packages/django/urls/conf.py", line 34, in include | |
web_1 | urlconf_module = import_module(urlconf_module) | |
web_1 | File "/usr/local/lib/python3.8/importlib/__init__.py", line 127, in import_module | |
web_1 | return _bootstrap._gcd_import(name[level:], package, level) | |
web_1 | File "<frozen importlib._bootstrap>", line 1014, in _gcd_import | |
web_1 | File "<frozen importlib._bootstrap>", line 991, in _find_and_load | |
web_1 | File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked | |
web_1 | File "<frozen importlib._bootstrap>", line 671, in _load_unlocked | |
web_1 | File "<frozen importlib._bootstrap_external>", line 783, in exec_module | |
web_1 | File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed | |
web_1 | File "/code/touristspots/api/urls.py", line 2, in <module> | |
web_1 | from touristspots.api.views import TouristSpotViewSet, FavoriteViewSet | |
web_1 | File "/code/touristspots/api/views.py", line 1, in <module> | |
web_1 | from dj_rest_auth.registration.views import SocialLoginView | |
web_1 | File "/usr/local/lib/python3.8/site-packages/dj_rest_auth/registration/views.py", line 11, in <module> | |
web_1 | from dj_rest_auth.registration.serializers import (SocialAccountSerializer, | |
web_1 | File "/usr/local/lib/python3.8/site-packages/dj_rest_auth/registration/serializers.py", line 171, in <module> | |
web_1 | class RegisterSerializer(serializers.Serializer): | |
web_1 | File "/usr/local/lib/python3.8/site-packages/dj_rest_auth/registration/serializers.py", line 173, in RegisterSerializer | |
web_1 | max_length=get_username_max_length(), | |
web_1 | File "/usr/local/lib/python3.8/site-packages/allauth/utils.py", line 69, in get_username_max_length | |
web_1 | max_length = User._meta.get_field(USER_MODEL_USERNAME_FIELD).max_length | |
web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/models/options.py", line 583, in get_field | |
web_1 | raise FieldDoesNotExist("%s has no field named '%s'" % (self.object_name, field_name)) | |
web_1 | django.core.exceptions.FieldDoesNotExist: User has no field named 'username' | |
^[[6~ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment