python - tutorial - Ya registrado en/appname/: El usuario modelo ya está registrado
register and login django (1)
Cuando define un administrador de usuario personalizado en admin.py
su aplicación, primero debe admin.py
registro del administrador de modelo de User
predeterminado antes de registrar el suyo propio.
admin.site.unregister(User)
admin.site.register(User, MyUserAdmin)
Estoy intentando conectar el usuario django.contrib.auth con mi propio perfil de usuario, y aparece un error "AlreadyRegistered" cuando estoy en el sitio.
Aquí está el rastreo:
Environment:
Request Method: GET
Request URL: myurl.com/django/appname/
Django Version: 1.4.2
Python Version: 2.6.8
Installed Applications:
(''django.contrib.auth'',
''django.contrib.contenttypes'',
''django.contrib.sessions'',
''django.contrib.sites'',
''django.contrib.messages'',
''django.contrib.staticfiles'',
''django.contrib.admin'',
''polls'',
''appname'',
''registration'',
''django.contrib.humanize'')
Installed Middleware:
(''django.middleware.common.CommonMiddleware'',
''django.contrib.sessions.middleware.SessionMiddleware'',
''django.middleware.csrf.CsrfViewMiddleware'',
''django.contrib.auth.middleware.AuthenticationMiddleware'',
''django.contrib.messages.middleware.MessageMiddleware'')
Traceback:
File "/usr/lib/python2.6/site-packages/django/core/handlers/base.py" in get_response
101. request.path_info)
File "/usr/lib/python2.6/site-packages/django/core/urlresolvers.py" in resolve
298. for pattern in self.url_patterns:
File "/usr/lib/python2.6/site-packages/django/core/urlresolvers.py" in url_patterns
328. patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/usr/lib/python2.6/site-packages/django/core/urlresolvers.py" in urlconf_module
323. self._urlconf_module = import_module(self.urlconf_name)
File "/usr/lib/python2.6/site-packages/django/utils/importlib.py" in import_module
35. __import__(name)
File "/var/www/mysite/mysite/urls.py" in <module>
3. admin.autodiscover()
File "/usr/lib/python2.6/site-packages/django/contrib/admin/__init__.py" in autodiscover
29. import_module(''%s.admin'' % app)
File "/usr/lib/python2.6/site-packages/django/utils/importlib.py" in import_module
35. __import__(name)
File "/var/www/mysite/appname/admin.py" in <module>
4. admin.site.register(User)
File "/usr/lib/python2.6/site-packages/django/contrib/admin/sites.py" in register
80. raise AlreadyRegistered(''The model %s is already registered'' % model.__name__)
Exception Type: AlreadyRegistered at /appname/
Exception Value: The model User is already registered
Estoy bastante seguro de que esto se debe a los modelos.py de mi aplicación, ya que creo que eso es todo lo que he cambiado de manera importante.
from django.db import models
from django.contrib.auth.models import User
from django.db.models.signals import post_save
class Tag(models.Model):
pics = models.ManyToManyField(''Picture'', blank=True)
name = models.CharField(max_length=30)
def __unicode__(self):
return self.name
class UserProfile(models.Model):
name = models.CharField(max_length=20)
date_joined = models.DateTimeField(''date joined'')
auth_user = models.OneToOneField(User)
def __unicode__(self):
return self.name
def create_user_profile(sender, instance, created, **kwargs):
if created:
UserProfile.objects.create(user=instance)
post_save.connect(create_user_profile, sender=User)
class Picture(models.Model):
name = models.CharField(max_length=100)
pub_date = models.DateTimeField(''date published'')
tags = models.ManyToManyField(''Tag'', blank=True)
owner = models.ForeignKey(''UserProfile'')
content = models.ImageField(upload_to=''instaton'')
def __unicode__(self):
return self.name
class Comment(models.Model):
content = models.CharField(max_length=500)
date = models.DateTimeField(''date commented'')
commenter = models.ForeignKey(''UserProfile'')
pic = models.ForeignKey(''Picture'')
def __unicode__(self):
return self.content