How to use django countries in registration form?

voger

I am trying to add django-countries in a registration form that will be used with django-allauth. As per instructions https://github.com/SmileyChris/django-countries I created a model

class UserProfile(models.Model):
    # Other things
    country = CountryField()

And a form

from django_countries.data import COUNTRIES

class SignupForm(forms.Form):
    # Other stuff
    country = forms.ChoiceField(choices=COUNTRIES, required=True)

    def signup(self, request, user):
        # Other Stuff
        user.userprofile.country = self.cleaned_data['country']

But when I visit the /accounts/signup/ page I get the form but for the countries select I get

<p><label for="id_country">Country:</label> <select id="id_country" name="country">
<option value="G">Q</option>
<option value="I">D</option>
<option value="K">Y</option>
 ...

Instead of country code and country name

Rajesh Kaushik

You should set choices like this:

from django_countries import countries
COUNTRY_CHOICES = tuple(countries)

class SignupForm(forms.Form):
    country = forms.ChoiceField(choices=COUNTRY_CHOICES, required=True)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to subclass registration form in django-registration

From Dev

How to make django registration form

From Dev

How to create a profile registration form in Django?

From Dev

How to use the Countries gem

From Dev

Django Registration Registration_form

From Dev

Django custom registration form

From Dev

Django Registration Redux custom registration form

From Dev

DJANGO: How do I order my input in my Registration Form?

From Dev

How to diagnose a Django registration form that appears to do nothing?

From Dev

Django how to get password after registration form is submitted?

From Dev

Django User Registration Form KeyError

From Dev

How to over-ride default registration form in Django-Registration version 1.0?

From Dev

How to over-ride default registration form in Django-Registration version 1.0?

From Dev

How to use Django parsley with crispy form in Django?

From Dev

How to customize the registration form in sylius?

From Dev

django-registration passing extra_context to Registration Form

From Dev

Django registration form on startpage, without redirect to loginpage

From Dev

NoReverseMatch: in the password reset form in Django-registration?

From Dev

AJAX Form post for Django registration 1.0

From Dev

Creating Custom user registration form Django

From Dev

django 1.7 User Registration form with profile picture

From Dev

Django - Registration form can't upload image

From Dev

Django user signup / registration form not working

From Dev

Python: how to use constructor with Django Form class?

From Dev

How to use a form to change the file of a Django ImageField?

From Dev

Use fosuser registration form on multiple urls

From Dev

How can I get the rest of a django-registration password reset form?

From Dev

form.isValid() always return false in custom registration form django

From Dev

Use pure HTML page for registration in Django

Related Related

  1. 1

    How to subclass registration form in django-registration

  2. 2

    How to make django registration form

  3. 3

    How to create a profile registration form in Django?

  4. 4

    How to use the Countries gem

  5. 5

    Django Registration Registration_form

  6. 6

    Django custom registration form

  7. 7

    Django Registration Redux custom registration form

  8. 8

    DJANGO: How do I order my input in my Registration Form?

  9. 9

    How to diagnose a Django registration form that appears to do nothing?

  10. 10

    Django how to get password after registration form is submitted?

  11. 11

    Django User Registration Form KeyError

  12. 12

    How to over-ride default registration form in Django-Registration version 1.0?

  13. 13

    How to over-ride default registration form in Django-Registration version 1.0?

  14. 14

    How to use Django parsley with crispy form in Django?

  15. 15

    How to customize the registration form in sylius?

  16. 16

    django-registration passing extra_context to Registration Form

  17. 17

    Django registration form on startpage, without redirect to loginpage

  18. 18

    NoReverseMatch: in the password reset form in Django-registration?

  19. 19

    AJAX Form post for Django registration 1.0

  20. 20

    Creating Custom user registration form Django

  21. 21

    django 1.7 User Registration form with profile picture

  22. 22

    Django - Registration form can't upload image

  23. 23

    Django user signup / registration form not working

  24. 24

    Python: how to use constructor with Django Form class?

  25. 25

    How to use a form to change the file of a Django ImageField?

  26. 26

    Use fosuser registration form on multiple urls

  27. 27

    How can I get the rest of a django-registration password reset form?

  28. 28

    form.isValid() always return false in custom registration form django

  29. 29

    Use pure HTML page for registration in Django

HotTag

Archive