2

I am wondering how I can get a user's location upon sign up using django.

May I have an example in code doing this in a form?

GeoIP likely does what I need but I am confused as to how to implement it.

Here is my current forms.py:

from django import forms
from captcha.fields import ReCaptchaField

from django.contrib.auth.models import User
from django.contrib.auth.forms import UserCreationForm

from .models import CustomUser

class UserCreateForm(UserCreationForm):
    email = forms.EmailField(required=True)
    captcha = ReCaptchaField()

class Meta:
    model = CustomUser # this may need to be changed to customuser
    fields = ("username", "email", "password1", "password2")

def save(self, commit=True):
    user = super(UserCreateForm, self).save(commit=False)
    user.email = self.cleaned_data["email"]
    if commit:
        user.save()
    return user
Alex
  • 486
  • 1
  • 7
  • 19

0 Answers0