I had installed djangorestframework-simplejwt with pip, so had i configure settings.py file for to use it, but, when i try to import the package, it doesn't has showing in importable package list.
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.BasicAuthentication',
'rest_framework_simplejwt.authentication.JWTAuthentication',
),
The importations list:
I simply rebuild all the project. Now, runed fine!
Related
After installing
social-auth-core
social-auth-app-django
on Django 4.0.6 and including to the INSTALLED_APPS and made everything on documents I got this error
'DjangoStrategy' object has no attribute 'get_backend'
This error happens when I click on login link on this URL http://localhost/login/google-oauth2/
In settings.py I have this backends
AUTHENTICATION_BACKENDS = (
'social_core.backends.google.GoogleOAuth2',
'django.contrib.auth.backends.ModelBackend',
)
Also, I am using channels and ASGI/Channels version 3.0.5
I created a frontend with vue.js using vue cli and webpack and the backend using django restframework where I am also implementing social authentication for google using restauth. Before I used the django webpack, the login and logout would work fine and as expected. (I should mention that I was using tokenauthentication) in my settings.py, file I had both the sessionauthentication as well as tokenauthentication enabled in the restframework authentication possibilities. The two settings being enabled never caused any trouble. However, after using the django webpack loader to render the frontend vue files using django templates, I would continuously get an error that said my csrf token was not present. The login would work fine in this case if I removed the sessionauthentication option out of the settings.py file however.
Does anyone know why this is happening?
https://medium.com/#rodrigosmaniotto/integrating-django-and-vuejs-with-vue-cli-3-and-webpack-loader-145c3b98501a
I used the above blog to implement the webpack loader functionality
I removed the 'rest_framework.authentication.SessionAuthentication', line from my settings.py after using the django-webpack-loader and the issue was resolved
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authtoken',
'rest_framework.authentication.BasicAuthentication',
'rest_framework.authentication.SessionAuthentication',
)
}
I basically changed it like below:
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authtoken'
'rest_framework.authentication.BasicAuthentication',
)
}
as you are probably using axios, you need to include these two lines in your main.js
/* configure axios to forward the csrftoken back to Django on POST requests */
axios.defaults.xsrfHeaderName = 'X-CSRFToken';
axios.defaults.xsrfCookieName = 'csrftoken';
I have a working Django REST API backend. I was previously using session authentication, but would like to move to token based for scaling across multiple servers. I have been researching this for a couple days now and I have not found an answer to my problem. I added the djangorestframework-jwt package to my application but when I try to authenticate is always returns:
{"non_field_errors":["Unable to login with provided credentials."]}
I see in the jwt package where this error is, and can follow the code back through the authentication process. I do not see any errors in the auth process. When I try to create a user with those credentials it says that a user already exists, so I know it is hitting the correct user table. I am not sure why the obtain_jwt_token endpoint will not authenticate my credentials. Below are relevant sections of my django app. Any help would be greatly appreciated. If I am leaving anything out that could help figure this out please let me know and I will upload it. Thanks,
app/settings.py
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticated',
),
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
),
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination',
'PAGE_SIZE': 100,}
app/urls.py
urlpatterns = patterns('',
# Api
url(r'^api/', include(router.urls)),
url(r'^api/stats', statsviews.StatsView.as_view()),
url(r'^api/testing', statsviews.TestView.as_view()),
url(r'^api/login', 'rest_framework_jwt.views.obtain_jwt_token'),
url(r'^api/logout', logout, {'next_page': '/api/login'}),
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')),
)
curl command
curl -d "email=test#myemail.com&password=test123" http://webhost.mywebsite.com:8080/api/login/
I have a very similar setup to you. A simple app, utilizing vanilla DRF JWT authentication. The only difference that I can tell is that I have rest_framework_jwt included in my INSTALLED_APPS list:
INSTALLED_APPS = (
...
# Third Party Dependencies
'rest_framework',
'rest_framework_jwt',
'corsheaders',
....
Try adding that and see where it gets you.
I encountered the same problem too,and finally found the way out.
following the quick start guide (http://www.django-rest-framework.org/tutorial/quickstart/) , using python manage.py migrate to create table structure; using python manage.py createsuperuser to create an initial user named admin with a password of "password123"; (attention: the passwords mismatch in guides)
now it should be ok.
$ curl -X POST -d "username=admin&password=password123" http://127.0.0.1:8000/api-token-auth/
{"token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwidXNlcl9pZCI6MiwiZW1haWwiOiJhZG1pbkA3amdvLmNvbSIsImV4cCI6MTQ3MDY0NjY4Mn0.Dg4KW5pHHJfuaRzjqHTu8kYIzkq8js9}
I'm using PyCharm 2.7.2, which is the latest version to date.
In my settings file for a django project, I used the following lines to configure my INSTALLED_APPS setting variable.
DJANGO_APPS = (
....
)
THIRD_PARTY_APPS = (
'south',
)
LOCAL_APPS = (
'blog',
)
INSTALLED_APPS = DJANGO_APPS + THIRD_PART_APPS + LOCAL_APPS
Now, south's features do not show up on manage.py. How do I run a custom manage.py command to get things working?
PyCharm doesn't understand concatenation for INSTALLED_APPS, there is an issue logged about it:
PY-8413 PyCharm settings.py parser should understand concatenation in INSTALLED_APPS initialization
Pycharm itself supports running south management commands. See relevant issue.
Looks like pycharm doesn't understand the structure of your project. Recheck if you configured it correctly.
I am trying to get django-allauth to work for a project. In my Django project, lets call it yali, I did a git clone.
I then moved the folder /django-allauth/allauth to root /yali. and then deleted django-allauth and all the licenses, READMEs ...etc
According to documentation, there are three things I should do:
I should add this to settings.py:
TEMPLATE_CONTEXT_PROCESSORS = (
...
"allauth.context_processors.allauth",
"allauth.account.context_processors.account"
)
AUTHENTICATION_BACKENDS = (
...
"allauth.account.auth_backends.AuthenticationBackend",
)
INSTALLED_APPS = (
...
'emailconfirmation',
'uni_form',
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.twitter',
'allauth.openid',
'allauth.facebook',
And then add this to urls.py
(r'^accounts/', include('allauth.urls')))
Doing so, gives me a 404 when navigating to http://localhost:8000/account
What am I missing here? The documentation is somewhat unclear here and even potentially wrong. It instructs to point urls.py to "accounts", while there is no "accounts" folder but "account"
The folder name has nothing to do with the url. The urls of your apps are defined in urls.py. You can put what you want, but you must use those same urls when navigating in the browser.
In your case, you must navigate to:
http://localhost:8000/accounts
If you have defined urls as:
(r'^anything/', include('allauth.urls')))
you should navigate to:
http://localhost:8000/anything