Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9002777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:36:58+00:00 2026-06-16T00:36:58+00:00

I feel rather stupid for asking this but I’ll do it anyway. The ‘Users’

  • 0

I feel rather stupid for asking this but I’ll do it anyway. The ‘Users’ API reference in the Django documentation “User authentication in Django” (v. 1.4) says that a username may only contain letters, digits, and the characters @, +, ., -, and _. Yet I can go into the Python shell and do the following:

>>> from django.contrib.auth.models import User
>>> u = User.objects.create_user('joe#')

Why doesn’t this raise an exception? I looked at the source code in ../contrib/auth/models.py and it doesn’t appear to be flagging invalid characters. What’s going on here? It would appear that if you want to catch an erroneous username, you’d have to do it via form validation.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:36:58+00:00Added an answer on June 16, 2026 at 12:36 am

    I guess the developers wanted to provide application developers with the flexibility so, that we could store special symbols. So, instead of validating the inputs at the model level, it is done in the form. You can find the form inside django.contrib.auth.form.UserCreationForm

    The snippet is here:

    You can see the validation using Regular Expression on the Username field.

    class UserCreationForm(forms.ModelForm):
        """
        A form that creates a user, with no privileges, from the given username and
        password.
        """
        error_messages = {
            'duplicate_username': _("A user with that username already exists."),
            'password_mismatch': _("The two password fields didn't match."),
        }
        username = forms.RegexField(label=_("Username"), max_length=30,
            regex=r'^[\w.@+-]+$',
            help_text = _("Required. 30 characters or fewer. Letters, digits and "
                          "@/./+/-/_ only."),
            error_messages = {
                'invalid': _("This value may contain only letters, numbers and "
                             "@/./+/-/_ characters.")})
        password1 = forms.CharField(label=_("Password"),
            widget=forms.PasswordInput)
        password2 = forms.CharField(label=_("Password confirmation"),
            widget=forms.PasswordInput,
            help_text = _("Enter the same password as above, for verification."))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've written this documentation of a rather simple class, but I feel it's not
I feel silly for asking, but how do I get plan value in this
I feel like such a noob asking this but, for some reason a horizontal
I feel like this is a rather simple question, but I can't seem to
This is very simple, but I'm being rather stupid about it. I have a
I feel rather silly actually asking this question as I am sure it will
I feel like a dork just for asking this, but I'm not getting any
I feel rather foolish as this is just a short question. I was reading
Feel free to close and/or redirect if this has been asked, but here's my
This may seem like a basic/stupid/obviously-answered question, but I wanted to check: why use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.