Im using https://github.com/python-social-auth/social-app-django
to make it easy to add new oauths to my django app.
I have added it to my settings files and filled in the keys.
urls.py
urlpatterns = [
path('', include('home.urls')),
path('admin/', admin.site.urls),
path('auth/', include('social_django.urls', namespace='social')),
]
settings.py
SOCIAL_AUTH_COINBASE_KEY = os.environ.get('COINBASE_ID')
SOCIAL_AUTH_COINBASE_SECRET = os.environ.get('COINBASE_SECRET')
AUTHENTICATION_BACKENDS = (
'social_core.backends.open_id.OpenIdAuth', # for Google authentication
'social_core.backends.google.GoogleOpenId', # for Google authentication
'social_core.backends.google.GoogleOAuth2', # for Google authentication
'social_core.backends.coinbase.CoinbaseOAuth2', # for Coinbase authentication
'django.contrib.auth.backends.ModelBackend',
)
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'social_django.context_processors.backends', # <- Here
'social_django.context_processors.login_redirect', # <- Here
],
},
},
]
INSTALLED_APPS = [
'user.apps.UserConfig',
'django.contrib.humanize',
'social_django',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
However when I see the oauth screen of coinbase, I press next, I get redirected to my redirect uri,
Then it gives me an error
HTTPError at /auth/complete/coinbase/
403 Client Error: Forbidden for url: https://api.coinbase.com/v2/user
I have been trying to fix this issue for hours now but I cant seem to find anything on this
Related
Django 4.0.3 and Python 3.10.2
I cant render a html file on my project. What am i missing? Main parts of code below.
Settings.py at INSTALLED_APPS:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'app1',
]
Settings.py at TEMPLATES:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
# 'DIRS': [r'project1\app1\templates\app1'],
'DIRS': [os.path.join(BASE_DIR, 'templates')],
},
]
Project-Urls:
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('app1.urls')), # main will be the name of your app
]
App1-Urls:
from django.urls import path
from . import views
urlpatterns = [
path('', views.simple_function, name='simple_function'),
]
Views:
def simple_function(request):
print("Print executes correctly, but the render doesn't")
return render(request, r'project1\app1\templates\app1\home.html')
Html file path: app1/templates/app1/home.html
Github of this project
Had to post this bunch of information to clarify.
instead of
return render(request, r'project1\app1\templates\app1\home.html')
try to write
return render(request, 'app1/home.html')
I updated my django google app engine application from 1.2 to 1.11 and do "revelant" steps (python 2.7), such as
urlpatterns = patterns('',
url(r'^$','froom.views.index', name='index'),
to
urlpatterns = [
url(r'^$',views.index, name='index'),
and start to use django cripsy forms.
while I run 1.2 version and post form, and get request.POST has dict value with posted form values,
however with 1.11 version, request.POST is empty.
request.POST = <QueryDict: {}>
I double check my ajax calls comes with
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
as noted here
My method stays same:
def edit_tenant(request, tenant_id=None):
if (request.method == 'POST'):
if tenant_id:
tenant_id_int = long(tenant_id)
tenant_org = db.get(db.Key.from_path('Tenant', tenant_id_int))
form = TenantForm(request.POST, instance = tenant_org, prefix = "edittenant")
django settings.py as below:
working version one's:
TEMPLATE_DIRS = (
os.path.join(os.path.dirname(__file__), 'templates'),
)
none working version one's:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.join(os.path.dirname(__file__), 'templates'),
os.path.join(os.path.dirname(__file__), 'myapplication'),
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
What could be issue that upgraded versions request.POST is empty?
The issue resolved with "#Daniel Roseman" comments which points to csrf token:
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.contenttypes',
'django.contrib.auth',
'myapplication',
'django_forms_bootstrap',
'crispy_forms',
)
when I add 'django.contrib.auth',
and update :
return render_to_response('edit_tenant.html')
to
return render(request, 'edit_tenant.html')
It puts
<input type='hidden' name='csrfmiddlewaretoken' value='itg3eY4YnesCy6p5enJS19txbMDI49Gf4UUEPQjOkUtyoEDBBO1L8nyborVD9prW' />
However I should have add 'django.middleware.csrf.CsrfViewMiddleware' to MIDDLEWARE_CLASSES as well:
MIDDLEWARE_CLASSES = (
'django.middleware.csrf.CsrfViewMiddleware',
'gaesessions.DjangoSessionMiddleware',
)
I had installed and configured django-admin-tools 0.8 following the documentation. Django version is 1.11.4, using virtualenv in project.
File settings.py:
INSTALLED_APPS = [
'admin_tools',
'admin_tools.theming',
'admin_tools.menu',
'admin_tools.dashboard',
'django.contrib.auth',
'django.contrib.sites',
'django.contrib.admin',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'atelierapp',
]
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
#'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'django.core.context_processors.request',
],
'loaders': [
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
'admin_tools.template_loaders.Loader',
]
},
},
]
File urls.py:
urlpatterns = [
#url(r'^admin/', admin.site.urls),
url(r'^admin_tools/', include('admin_tools.urls')),
]
But when I try to enter the admin panel, I get a 404 error.
Screenshot
What is the problem I'm not seeing?
Thank you for your time.
According to the documentation
Prerequisite
In order to use django-admin-tools you obviously need to have configured your Django admin site. If you didn’t, please refer to the relevant django documentation.
However I noticed in your urls that you have:
#url(r'^admin/', admin.site.urls),
Have you tried removing the # tag?
I am using django-registraion for authentication of users. I did install django-registration via pip and added in the settings.py file. However it is still giving me the Templtate doesnot exist error. Here's the error:
TemplateDoesNotExist at /accounts/login/
registration/login.html
Request Method: GET
Request URL: http://127.0.0.1:8000/accounts/login/?next=/
Django Version: 1.11.3
Exception Type: TemplateDoesNotExist
Exception Value: registration/login.html
Exception Location: C:\Python34\lib\site- packages\django\template\loader.py in select_template, line 53
Here's the code:
from django.conf.urls import url
from django.contrib import admin
from django.contrib.auth.views import login, logout
from chat.views import index
from django.conf.urls import include
urlpatterns = [
url('^', include('django.contrib.auth.urls')),
url(r'^admin/', admin.site.urls),
url(r'^$',index, name='homepage'), # The start point for index view
url(r'^accounts/login/$', login, name='login'), # The base django login view
url(r'^accounts/logout/$', logout, name='logout'), # The base django logout view
in the settings.py file:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.humanize',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'chat',
'registration',
]
This is the structure of my django project.
it seems the templates folder is at the root directory, so you need to change your settings to this
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
BASE_DIR + '/templates/',
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
# Insert your TEMPLATE_CONTEXT_PROCESSORS here or use this
# list of context processors
],
'debug': True
},
},
]
I've overriden Django-allauth templates in my Django project just creating a new folder "account" in templates folder. This works during deployment on Windows but when I moved the project to DigitalOcean VPS, it is looking for old templates (in allauth app) so I see old styled allauth pages.
This is the structure:
firstapp\
authapp\
templates\
account\
email.html
login.html
anotherapp\
I tried to switch allauth apps and my authapp in INSTALLED_APPS but it doesn't seem to work.
And this is my settings.py INSTALLED_APPS.
INSTALLED_APPS = (
'django.contrib.auth',
'mainapp',
'django.contrib.admin',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.sites',
'django.contrib.staticfiles',
'crispy_forms',
'super_inlines',
'django_tables2',
'quizzesapp',
'ordersapp',
'django_extensions',
'authapp',
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.google',
'allauth.socialaccount.providers.facebook',
'languagesapp',
'widget_tweaks',
'localflavor',
'paypal',
'paypal.standard.ipn',
'nested_inline',
'django_forms_bootstrap'
)
What do you thing I should do?
EDIT:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'django.core.context_processors.i18n',
# 'django.core.context_processors.request',
# "django.contrib.auth.context_processors.auth",
# "allauth.account.context_processors.account",
# "allauth.socialaccount.context_processors.socialaccount",
],
},
},
]