Question

I have deployed a Django application on DigitalOcean using ngnix, gunicorn and a Postgresql database. Everything works just fine and when I run python manage.py syncdb and I'm able to create a user which populates my DB nicely.

Problem I'm having is that when I try to login to the Django admin interface I get prompted that I'm using the wrong username and/or password. I'm pretty sure the credentials are right as I have tried setting up the db multiple times.

Any ideas why Django thinks I'm inputing the wrong user info?

Thanks!

SETTINGS.py looks like

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'XXXXXXXXXXXXXXX'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

TEMPLATE_DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
)

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

ROOT_URLCONF = 'qvido.urls'

WSGI_APPLICATION = 'qvido.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.6/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'mydbname',
        'USER': 'user',
        'PASSWORD': 'pass!',
        'HOST': 'localhost',
        'ROOT': '',
    }
}

# Internationalization
# https://docs.djangoproject.com/en/1.6/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.6/howto/static-files/

STATIC_ROOT = '/webapps/django-env/static/'

STATIC_URL = '/static/'

WSGI.py looks like

import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "qvido.settings")

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

EDIT

Ok, I aslo tried doing python manage.py dbshell and the select * from auth_user; I see the user I've created but still can't log in with it. So strange.

Était-ce utile?

La solution 2

So, I found the answer to why this was happening and indeed @scriptmonster was correct.

When I installed Django, Gunicorn etc. in my virtual-env I used sudo pip install which installed these outside of my virtaul-env.

I ran sudo chown -R myuser:myuser /webapps/myenv and then ran pip install django and pip install gunicorn again and everything worked just fine.

Autres conseils

I apologize for the late answer, but I believe that this may be useful to someone.

I was having this same issue. After reading all of the comments to the original question, I was able to figure out what had happened.

During development, I had switched databases from an old test db to a new one which included all of the required tables rather than just changing the existing db. I had only changed the settings.py file to update the location of the new db, and did not touch the wsgi.py file. After migrating to the new db and removing the old file from the project, my admin user did not exist within the new database.

Based on comments by @Torsten Engelbrecht and the OP, all I needed to do was run the command suggested by @Alen thomas to make it functional again:

python manage.py createsuperuser

At this point I was able to set up the same admin account I'd used before, since it no longer existed. Now it all works fine. It might seem a little silly, but it pays to check the

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top