https://django-rest-auth.readthedocs.io/en/latest/installation.html here is the official docs about social login in django-rest-auth. they say the way to make the LoginView(GithubLogin, FacebookLogin, etc..) inheriting SocialLoginView like this.
from allauth.socialaccount.providers.github.views import GitHubOAuth2Adapter
from allauth.socialaccount.providers.oauth2.client import OAuth2Client
from rest_auth.registration.views import SocialLoginView
class GithubLogin(SocialLoginView):
adapter_class = GitHubOAuth2Adapter
callback_url = CALLBACK_URL_YOU_SET_ON_GITHUB
client_class = OAuth2Client
but when i try to access the url with this as as.view(), they always say
{
"non_field_errors": [
"View is not defined, pass it as a context variable"
]
}
I tried the best. I have been suffering it for a few days. plz anybody save my life..
What's wrong with it? I've searched a lots but there wasn't any good answer for me.
So I've done a little digging and I discovered the problem.
The django-rest-auth package is no longer maintained and thus does not support modern versions of django rest framework. At the time of this post, up to version 3.10.3 of DRF is verified to work and I can verify that version 3.12.1 (and presumably onward) does not.
It looks like the project has been forked to dj-rest-auth and is receiving further support there. I would recommend migrating to that package.
You can read more about the decision to stop maintenance and fork to a new repository here.
Related
Hey i have one question about creating superuser with djangorestframework.
I want to create superuser with POST request using DRF 3.14
How should i do that if i'm using Android as a client for example?
Assuming you know what you are doing (superusers are quite powerful in Django), I suggest you include the following snippet in your DRF view:
from django.core import management
management.call_command('createsuperuser', **yourargs)
Full documentation can be found in the Django docs
I am going through the official tutorial provided by graphene-python for their library.
I, like a few others I have seen online, am having some serious issues trying to simply import the schema file within the project folder (project_name/schema.py). For reference, the project_name is cookbook as it is denoted within the tutorial.
This is within my settings.py:
GRAPHENE = {
'SCHEMA': 'cookbook.schema.schema'
}
and this is in the schema file tiself (project_name/schema.py):
import graphene
import cookbook.schema
class Query(cookbook.schema.Query, graphene.ObjectType):
# This class will inherit from multiple Queries
# as we begin to add more apps to our project
pass
schema = graphene.Schema(query=Query)
The error that I am getting is:
Could not import 'cookbook.schema.schema' for Graphene setting 'SCHEMA'. AttributeError: module 'cookbook' has no attribute 'schema'.
I have also tried a few other tutorials as well, but haven't had any luck. My project is on django 2.0.2 and graphene 2.0.1. Any help would be much appreciated.
Did you add this to your installed apps?
INSTALLED_APPS = [
'graphene_django',
]
the error says that cookbook has no attribute schema.
Therefore the import cookbook.schema is not working in your schema.py
the example says
import cookbook.ingredients.schema
I actually had incompatible versions of Django, Graphene and Django-environ.
To solve, I made a virtualenv using mkvirtualenv. After that, I was able to follow this tutorial without any issues. It is capable of being stood up without a virtual environment, but it was far easier to just define one and get moving with a clean slate.
I've been working on a Django-Mongodb application. I was trying to use django-registration module in my project, but never got it to work.
https://github.com/lig/django-registration-me
Have anyone used django-registration in their django-nonrel? If you do, can you point me some instructions? What should User model look like since it is in django-nonrel?
Thanks in advance,
Since nobody really answered it, and I figured it out. I will just answer my own question as the reference for others who might be having the same problem.
I found it easier to use Mongoengine Authentication backend on top of Django authentication. Use the following in settings.py.
AUTHENTICATION_BACKENDS = (
'mongoengine.django.auth.MongoEngineBackend',
)
SESSION_ENGINE = 'mongoengine.django.sessions'
https://mongoengine-odm.readthedocs.org/en/latest/django.html
Apart from that you use pretty much the same code as in regular django, and a bit different at accessing the user from request. Just need to:
from mongoengine.django.auth import User
And if you use form in django, you probably end up using form for mongodb instead.
https://github.com/jschrewe/django-mongodbforms
I'm new to django and been designing some basic models that contain FileFields.
Here is an example of my model:
class Sample(models.Model):
pub_date = models.DateTimeField('Publish Date', default=datetime.now)
upfile = models.FileField(upload_to='samples/')
I have tested the file upload via admin, but now I'm looking for other solutions to submit files via REST API. My first searches lead to Piston but most examples don't seem to involve models, only file upload to websites.
My objective is to parse directories, for example with os.walk, and submit the files and fill the model with the file info.
That said I'm looking for suggestions and leads in order to start investigating.
Thanks in advance!
You probably shouldn't be looking to piston for new builds anymore. It's essentially unmaintained and has been for a while now. django-tastypie and django-rest-framework are your best bets, although there's also a bunch of less fully featured frameworks cropping up.
REST framework supports standard form-encoded file uploads, see http://django-rest-framework.org/api-guide/fields.html#filefield
I'm not sure about tastypie's support for file uploads.
I've went back to the basics and decided to try creating a local script that reads calls File and the Sample Model. Since I will submit files directly from the same server, this solution immensely more simple than using a REST API, which delivers more flexibility than what I need.
This was my solution:
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
import sys
sys.path.append('/opt/proj')
sys.path.append('/opt/proj/web')
from django import db
from django.core.files import File
from django.utils import timezone
from web.myapp.models import Sample
filesample = File(open(sys.argv[1],'rb'))
filesample.name = os.path.basename(filesample.name)
Sample(upfile=filesample, pub_date=timezone.now()).save()
Looking back this was incredibly simple, but I hope it can help someone with the same problem.
Feel free to comment.
Thanks!
I want to implement user registration using captcha in Django.
The workflow of django-registration app is a great, but it doesn't have captcha.
What captcha would you recommend to use with it?
Are there some other variants of registration+captcha or useful links on the topic?
This should work with Django-1.1 and don't be too hard to install.
django-registration is pretty extendable. One way to extend it is to provide a custom registration form. I'd recommend to use reCaptcha, e.g. with the widget and form field from here (archived). Then it is as simple as writing a custom form class and registration backend (which is simpler than it sounds):
from registration.backends.default import DefaultBackend
from registration.forms import RegistrationForm
class RecaptchaRegistrationForm(RegistrationForm)
recaptcha = ReCaptchaField(label="I'm a human")
class RecaptchaRegistrationBackend(DefaultBackend):
def get_form_class(self, request):
return RecaptchaRegistrationForm
The last step is to tell django-registration to use your backend. That step is described in the docs (I couldn't find a HTML version of the docs, sorry)
I've just had this problem, but the solution is dead simple.
I'm using django-registration, and I want a reCAPTCHA field for user registration. In just 1 minute:
download django-recaptcha (pip install django-recaptcha)
install it on your project. That is, copy the "captcha" folder to your project, add "captcha" to INSTALLED_APPS and add your RECAPTCHA_PUBLIC_KEY and RECAPTCHA_PRIVATE_KEY keys to settings.py too (as described in the installation instructions)
open registration/forms.py and add this field inside class RegistrationForm(forms.Form):
captcha = ReCaptchaField()
you will also have to import:
from captcha.fields import ReCaptchaField
And that's it. Less than a minute.
For those like me arriving late to the thread, there are a bunch of solutions out there now, which are pretty easy to install:
http://code.google.com/p/django-simple-captcha/
http://code.google.com/p/django-captcha/
https://github.com/inueni/django-captcha-field
https://github.com/justquick/django-math-captcha
https://github.com/marconi/django-mollom which uses the third-party Mollom service (which provides captcha and spam-filtering services).
I've successfully setup Django Mollom and Django Simple Captcha, and the hardest part was yak shaving around installing PIL on my Mac. Implementing the code was as straightforward as the docs for each would suggest.