简体   繁体   中英

Django project how to find admin username and password

I found a Django project and failed to get it running in Docker container in the following way:

  1. git clone https://github.com/hotdogee/django-blast.git

  2. $ cat requirements.txt in this files the below dependencies had to be updated:

    • kombu==3.0.30
    • psycopg2==2.8.6

I have the following Dockerfile:

FROM python:2
ENV PYTHONUNBUFFERED=1
RUN apt-get update && apt-get install -y postgresql-client
WORKDIR /code
COPY requirements.txt /code/
RUN pip install -r requirements.txt
COPY . /code/

For docker-compose.yml I use:

version: "3"

services:
  dbik:
    image: postgres
    volumes:
      - ./data/dbik:/var/lib/postgresql/data
      - ./scripts/install-extensions.sql:/docker-entrypoint-initdb.d/install-extensions.sql

    environment:
      - POSTGRES_DB=django_i5k
      - POSTGRES_USER=django
      - POSTGRES_PASSWORD=postgres
    ports:
      - 5432:5432


  web:
    build: .
    command: python manage.py runserver 0.0.0.0:8000
    volumes:
      - .:/code
    ports:
      - "8000:8000"
    depends_on:
      - dbik
    links:
      - dbik

$ cat scripts/install-extensions.sql 
CREATE EXTENSION hstore;

I had to change:

$ vim i5k/settings_prod.py
DATABASES = {
    'default': {
    'ENGINE': 'django.db.backends.postgresql_psycopg2',
    'NAME': 'postgres',
    'USER': 'postgres',
    'PASSWORD': 'postgres',
    'HOST': 'db',
    'PORT': '5432',
    }
}

Please below the logs after I ran

docker-compose build
docker-compose up
Attaching to djangoblast_dbik_1, djangoblast_db_1, djangoblast_web_1
dbik_1  | 
db_1    | 
dbik_1  | PostgreSQL Database directory appears to contain a database; Skipping initialization
dbik_1  | 
db_1    | PostgreSQL Database directory appears to contain a database; Skipping initialization
db_1    | 
dbik_1  | 2021-05-19 10:45:54.221 UTC [1] LOG:  starting PostgreSQL 13.3 (Debian 13.3-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
db_1    | 2021-05-19 10:45:55.264 UTC [1] LOG:  starting PostgreSQL 13.3 (Debian 13.3-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
db_1    | 2021-05-19 10:45:55.264 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
dbik_1  | 2021-05-19 10:45:54.221 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
db_1    | 2021-05-19 10:45:55.264 UTC [1] LOG:  listening on IPv6 address "::", port 5432
dbik_1  | 2021-05-19 10:45:54.221 UTC [1] LOG:  listening on IPv6 address "::", port 5432
dbik_1  | 2021-05-19 10:45:54.226 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
dbik_1  | 2021-05-19 10:45:54.231 UTC [26] LOG:  database system was shut down at 2021-05-19 10:45:07 UTC
db_1    | 2021-05-19 10:45:55.271 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
dbik_1  | 2021-05-19 10:45:54.237 UTC [1] LOG:  database system is ready to accept connections
db_1    | 2021-05-19 10:45:55.283 UTC [26] LOG:  database system was shut down at 2021-05-19 10:45:18 UTC
db_1    | 2021-05-19 10:45:55.292 UTC [1] LOG:  database system is ready to accept connections
web_1   | /usr/local/lib/python2.7/site-packages/social/apps/django_app/default/models.py:29: RemovedInDjango19Warning: Model class social.apps.django_app.default.models.UserSocialAuth doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.
web_1   |   class UserSocialAuth(models.Model, DjangoUserMixin):
web_1   | 
web_1   | /usr/local/lib/python2.7/site-packages/social/apps/django_app/default/models.py:67: RemovedInDjango19Warning: Model class social.apps.django_app.default.models.Nonce doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.
web_1   |   class Nonce(models.Model, DjangoNonceMixin):
web_1   | 
web_1   | /usr/local/lib/python2.7/site-packages/social/apps/django_app/default/models.py:78: RemovedInDjango19Warning: Model class social.apps.django_app.default.models.Association doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.
web_1   |   class Association(models.Model, DjangoAssociationMixin):
web_1   | 
web_1   | /usr/local/lib/python2.7/site-packages/social/apps/django_app/default/models.py:91: RemovedInDjango19Warning: Model class social.apps.django_app.default.models.Code doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.
web_1   |   class Code(models.Model, DjangoCodeMixin):
web_1   | 
web_1   | /code/suit/admin.py:5: RemovedInDjango19Warning: django.contrib.contenttypes.generic is deprecated and will be removed in Django 1.9. Its contents have been moved to the fields, forms, and admin submodules of django.contrib.contenttypes.
web_1   |   from django.contrib.contenttypes import generic
web_1   | 
web_1   | /usr/local/lib/python2.7/site-packages/social/apps/django_app/default/models.py:29: RemovedInDjango19Warning: Model class social.apps.django_app.default.models.UserSocialAuth doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.
web_1   |   class UserSocialAuth(models.Model, DjangoUserMixin):
web_1   | 
web_1   | /usr/local/lib/python2.7/site-packages/social/apps/django_app/default/models.py:67: RemovedInDjango19Warning: Model class social.apps.django_app.default.models.Nonce doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.
web_1   |   class Nonce(models.Model, DjangoNonceMixin):
web_1   | 
web_1   | /usr/local/lib/python2.7/site-packages/social/apps/django_app/default/models.py:78: RemovedInDjango19Warning: Model class social.apps.django_app.default.models.Association doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.
web_1   |   class Association(models.Model, DjangoAssociationMixin):
web_1   | 
web_1   | /usr/local/lib/python2.7/site-packages/social/apps/django_app/default/models.py:91: RemovedInDjango19Warning: Model class social.apps.django_app.default.models.Code doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.
web_1   |   class Code(models.Model, DjangoCodeMixin):
web_1   | 
web_1   | /code/suit/admin.py:5: RemovedInDjango19Warning: django.contrib.contenttypes.generic is deprecated and will be removed in Django 1.9. Its contents have been moved to the fields, forms, and admin submodules of django.contrib.contenttypes.
web_1   |   from django.contrib.contenttypes import generic
web_1   | 
web_1   | Performing system checks...
web_1   | 
web_1   | System check identified no issues (0 silenced).
web_1   | 
web_1   | You have unapplied migrations; your app may not work properly until they are applied.
web_1   | Run 'python manage.py migrate' to apply them.
web_1   | May 19, 2021 - 06:45:57
web_1   | Django version 1.8, using settings 'i5k.settings'
web_1   | Starting development server at http://0.0.0.0:8000/
web_1   | Quit the server with CONTROL-C.
web_1   | /code/rest_framework_swagger/urlparser.py:4: RemovedInDjango19Warning: django.utils.importlib will be removed in Django 1.9.
web_1   |   from django.utils.importlib import import_module
web_1   | 
web_1   | [19/May/2021 06:46:12]"GET / HTTP/1.1" 404 5610
web_1   | [19/May/2021 06:46:12]"GET /favicon.ico HTTP/1.1" 404 5643

Finally, I ran docker-compose run web python manage.py migrate .

在此处输入图像描述

How do I find the admin's username and password?

Thank you in advance

The script code not have command line for create superuser, please try this in terminal and you have user

docker-compose run web python manage.py createsuperuser
  • Try some data
Username: admin
Email address: admin@gmail.com
Password: admin@123
Password (again): admin@123
Superuser created successfully.

You can easily create another administrator using python manage.py createsuperuser .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM