Django-Registration: Email as username

Dear fellow Django Coder, I think this is the best way to do it. Good luck! First step, is to create the form you’d like to use. project/accounts/forms.py from django import forms from registration.forms import RegistrationForm from django.contrib.auth.models import User class Email(forms.EmailField): def clean(self, value): super(Email, self).clean(value) try: User.objects.get(email=value) raise forms.ValidationError(“This email is already registered. … Read more

Removing help_text from Django UserCreateForm

You can set help_text of fields to None in __init__ from django.contrib.auth.forms import UserCreationForm from django import forms class UserCreateForm(UserCreationForm): email = forms.EmailField(required=True) def __init__(self, *args, **kwargs): super(UserCreateForm, self).__init__(*args, **kwargs) for fieldname in [‘username’, ‘password1’, ‘password2’]: self.fields[fieldname].help_text = None print UserCreateForm() output: <tr><th><label for=”id_username”>Username:</label></th><td><input id=”id_username” type=”text” name=”username” maxlength=”30″ /></td></tr> <tr><th><label for=”id_password1″>Password:</label></th><td><input type=”password” name=”password1″ id=”id_password1″ /></td></tr> … Read more

Creating a extended user profile

You can implement it using post_save on the user: from django.db.models.signals import post_save from models import UserProfile from django.contrib.auth.models import User def create_profile(sender, **kwargs): user = kwargs[“instance”] if kwargs[“created”]: profile = users.models.UserProfile() profile.setUser(sender) profile.save() post_save.connect(create_profile, sender=User) Edit: Another possible solution, which is tested and works (I’m using it on my site): from django.db import models … Read more

Get user information in django templates

An alternate method for current Django versions: {% if user.is_authenticated %} <p>Welcome, {{ user.get_username }}. Thanks for logging in.</p> {% else %} <p>Welcome, new user. Please log in.</p> {% endif %} Note: Use request.user.get_username() in views & user.get_username in templates. Preferred over referring username attribute directly. Source This template context variable is available if a … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)