BurkovBA / django-rest-framework-mongoengine-example

django-rest-framework-mongoengine-example
83 stars 45 forks source link

Example can't run correctly. #6

Closed petrewoo closed 6 years ago

petrewoo commented 6 years ago

Environment:

Request Method: GET Request URL: http://localhost:8888/api/

Django Version: 1.9 Python Version: 2.7.14 Installed Applications: ['django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'rest_framework', 'rest_framework_mongoengine', 'mongoengine.django.mongo_auth', 'app', 'users'] Installed Middleware: ['django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware']

Traceback:

File "/Users/alex/.virtualenvs/drfm_demo/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response

  1. response = self.process_exception_by_middleware(e, request)

File "/Users/alex/.virtualenvs/drfm_demo/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response

  1. response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/Users/alex/.virtualenvs/drfm_demo/lib/python2.7/site-packages/django/views/decorators/csrf.py" in wrapped_view

  1. return view_func(*args, **kwargs)

File "/Users/alex/.virtualenvs/drfm_demo/lib/python2.7/site-packages/django/views/generic/base.py" in view

  1. return self.dispatch(request, *args, **kwargs)

File "/Users/alex/.virtualenvs/drfm_demo/lib/python2.7/site-packages/rest_framework/views.py" in dispatch

  1. response = self.handle_exception(exc)

File "/Users/alex/.virtualenvs/drfm_demo/lib/python2.7/site-packages/rest_framework/views.py" in dispatch

  1. self.initial(request, *args, **kwargs)

File "/Users/alex/.virtualenvs/drfm_demo/lib/python2.7/site-packages/rest_framework/views.py" in initial

  1. self.perform_authentication(request)

File "/Users/alex/.virtualenvs/drfm_demo/lib/python2.7/site-packages/rest_framework/views.py" in perform_authentication

  1. request.user

File "/Users/alex/.virtualenvs/drfm_demo/lib/python2.7/site-packages/rest_framework/request.py" in getattribute

  1. return super(Request, self).getattribute(attr)

File "/Users/alex/.virtualenvs/drfm_demo/lib/python2.7/site-packages/rest_framework/request.py" in user

  1. self._authenticate()

File "/Users/alex/.virtualenvs/drfm_demo/lib/python2.7/site-packages/rest_framework/request.py" in _authenticate

  1. user_auth_tuple = authenticator.authenticate(self)

File "/Users/alex/.virtualenvs/drfm_demo/lib/python2.7/site-packages/rest_framework/authentication.py" in authenticate

  1. if not user or not user.is_active:

File "/Users/alex/.virtualenvs/drfm_demo/lib/python2.7/site-packages/django/utils/functional.py" in inner

  1. self._setup()

File "/Users/alex/.virtualenvs/drfm_demo/lib/python2.7/site-packages/django/utils/functional.py" in _setup

  1. self._wrapped = self._setupfunc()

File "/Users/alex/.virtualenvs/drfm_demo/lib/python2.7/site-packages/django/contrib/auth/middleware.py" in

  1. request.user = SimpleLazyObject(lambda: get_user(request))

File "/Users/alex/.virtualenvs/drfm_demo/lib/python2.7/site-packages/django/contrib/auth/middleware.py" in get_user

  1. request._cached_user = auth.get_user(request)

File "/Users/alex/.virtualenvs/drfm_demo/lib/python2.7/site-packages/django/contrib/auth/init.py" in get_user

  1. user_id = _get_user_session_key(request)

File "/Users/alex/.virtualenvs/drfm_demo/lib/python2.7/site-packages/django/contrib/auth/init.py" in _get_user_session_key

  1. return get_user_model()._meta.pk.to_python(request.session[SESSION_KEY])

File "/Users/alex/.virtualenvs/drfm_demo/lib/python2.7/site-packages/django/contrib/sessions/backends/base.py" in getitem

  1. return self._session[key]

File "/Users/alex/.virtualenvs/drfm_demo/lib/python2.7/site-packages/django/contrib/sessions/backends/base.py" in _get_session

  1. self._session_cache = self.load()

File "/Users/alex/.virtualenvs/drfm_demo/lib/python2.7/site-packages/django/contrib/sessions/backends/db.py" in load

  1. expire_date__gt=timezone.now()

File "/Users/alex/.virtualenvs/drfm_demo/lib/python2.7/site-packages/django/db/models/manager.py" in manager_method

  1. return getattr(self.get_queryset(), name)(*args, **kwargs)

File "/Users/alex/.virtualenvs/drfm_demo/lib/python2.7/site-packages/django/db/models/query.py" in get

  1. num = len(clone)

File "/Users/alex/.virtualenvs/drfm_demo/lib/python2.7/site-packages/django/db/models/query.py" in len

  1. self._fetch_all()

File "/Users/alex/.virtualenvs/drfm_demo/lib/python2.7/site-packages/django/db/models/query.py" in _fetch_all

  1. self._result_cache = list(self.iterator())

File "/Users/alex/.virtualenvs/drfm_demo/lib/python2.7/site-packages/django/db/models/query.py" in iter

  1. results = compiler.execute_sql()

File "/Users/alex/.virtualenvs/drfm_demo/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in execute_sql

  1. cursor.execute(sql, params)

File "/Users/alex/.virtualenvs/drfm_demo/lib/python2.7/site-packages/django/db/backends/utils.py" in execute

  1. return super(CursorDebugWrapper, self).execute(sql, params)

File "/Users/alex/.virtualenvs/drfm_demo/lib/python2.7/site-packages/django/db/backends/utils.py" in execute

  1. return self.cursor.execute(sql, params)

File "/Users/alex/.virtualenvs/drfm_demo/lib/python2.7/site-packages/django/db/utils.py" in exit

  1. six.reraise(dj_exc_type, dj_exc_value, traceback)

File "/Users/alex/.virtualenvs/drfm_demo/lib/python2.7/site-packages/django/db/backends/utils.py" in execute

  1. return self.cursor.execute(sql, params)

File "/Users/alex/.virtualenvs/drfm_demo/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py" in execute

  1. return Database.Cursor.execute(self, query, params)

Exception Type: OperationalError at /api/ Exception Value: no such table: django_session

BurkovBA commented 6 years ago

Hi, @petrewoo.

Did you run python manage.py makemigrations and python manage.py migrate before launching the server?

You should create those django tables in SQLite with initial migration to keep django happy.

petrewoo commented 6 years ago

Hi, @BurkovBA I didn't do that before launching the server. Can you tell me why i should do this? I use postman and httpie request http://localhost:8888/api/ everything works fine. But when i use chrome this error occurred.😂😂 I will try again litter.

BurkovBA commented 6 years ago

@petrewoo Probably, the difference between postman and browser is due to the format of response.

When you're using postman, it requests JSON response, so JSONRenderer is used by Django REST Framework internally.

But when you go with browser, Django REST Framework is trying to use the Browsable API, which relies on core django functionality. And django wants its tables in relational database created for normal functioning - that's why you were getting the error.

petrewoo commented 6 years ago

@BurkovBA After run python manage.py makemigrations and python manage.py migrate before launching the server, It works finally. Thank you so much.