How to create api endpoint to create super user in django - django

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

Related

Django rest_api and React

I am creating an am using Django and React. I have created custom user model api in Django using rest-framework, but i am confused about the whole login and signup system. Do we create login and signup modules in Django or React.
Can anyone please guide me through it, or suggest any tutorial.
You create the templates (login, signup, etc. pages) in React and connect them to DRF. There are multiple ways to perform authentication. Take a look to Authentication docs on DRF. https://django-rest-framework.org/api-guide/authentication

Build react form based on serializer of Django Rest Framework

I want to build web app where users can add different ads for sale(cars,apartments, gadgets etc...) and each of this categories models in django are specific and need specific fields in form for creating ad. Creating this forms using django is easy by using ModelForms.
DRF documentation says that
A serializer class is very similar to a Django Form class, and includes similar validation flags on the various fields..... . So I guess I will create form on base of serializers.
My question is: How make a single React component which will render form on base of different serializers that frontend gets from Django-Rest-Framework?
Please any advice or links where I can read about this . If you need I can share some code . Thank you in advance.
Quite a late response, but here's some workaround.
You could check this npm package that convert JSON into React Form: https://www.npmjs.com/package/react-jsonschema-form
You could generate the JSON description from your Django model, by looping among attribute.
It's not straightforward but it worked fine for me.

Django registration that works well with django-authtools

I have a Django app that uses django-authtools which provides a custom auth model so that I can use email as user id.
I am wondering if there is a reusable app that I can reuse for doing registrations. Something like django-registration-redux but that works well with the just using email as user id. Or can django-registration-redux be used in this scenario?
I figured that what I was trying to achieve is achieved by using django-allauth instead. This link shows the way how to achieve it:
I think I can achieve what I am trying to do how it is specified in Remove 'username' field from django-allauth. So I guess

Creating a User Registration Page using MongoEngine

I am currently working an a webapp, using mongoengine and django, which will require users to create an account from a registration page. I know MongoEngine has an authentication backend, but does it also include a registration form, etc..., like django itself does? If not, are there any example projects which show how to implement this? The only open-source mongoengine project I've found is django-mumblr, but I can't find the examples I want in it.
I'm not interested in alternative options, such as MongoKit or mango for handling authentication.
I am just getting started with django and mongoDB, so please excuse my lack of knowledge. Thanks in advance for the help!
Not tried it out yet, but https://github.com/lig/django-registration-me by http://twitter.com/#!/lig1 looks like it could be a good bet.

Easy-to-use django captcha or registration app with captcha?

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.