Muallif
July 12, 2024
169Django loyihani herokuga yuklash bo'yicha qo'llanma Ushbu maqolada djangoni herokuga terminal orqali yuklash ketma-ket liklarini ko'rib chiqamiz
Bo'limlar
Virtual muhit ichida ekanligizga ishonch hosil qiling
pip install gunicorn dj-database-url whitenoise psycopg2-binary
pip freeze > requirements.txt
-> bu o'rnatilgan dasturlarni herokuga tanitadi va heroku shundagi package larni o'rnatadipython3 --version
echo "python-3.10.4" > runtime.txt
python versiyasi o'zniga o'zizni python versiyayizni yozingecho "web: gunicorn PROJECT_NOMI.wsgi" > Procfile
Bu yerda PROJECT_NOMI
o'rniga wsgi.py fayli turgan papkani yozing.<code> INSTALLED_APPS = [ 'whitenoise.runserver_nostatic', # ... ]whitenoise static filelarni saqlashi uchun installed apps ichiga qo'shishimiz kerak
ALLOWED_HOSTS = ['127.0.0.1', '.herokuapp.com']
DEBUG = False
MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', # whitenoise ni shu yerga qo'shing 'whitenoise.middleware.WhiteNoiseMiddleware', # ... ]
Bu yerda sal e'tiborli bo'ling. Ya'ni whitenoise ni Djangoning o'zida mavjud bo'lgan SecurityMiddleware
tagiga qo'shing
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql', 'NAME': 'DATABASE NOMI', 'USER': 'USER', 'PASSWORD': "PAROL", 'HOST': '127.0.0.1', 'PORT': '5432', } } import dj_database_url db_from_env = dj_database_url.config(conn_max_age=500) DATABASES['default'].update(db_from_env)Shularni
sqLite3
database o'rniga qo'shib qo'yingSTATIC_ROOT = BASE_DIR / 'static' STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'Bu static filelarning ishlashi uchun. Static filelarhaqida batafsil bu yerda o'qishiz mumkin.
sudo -u postgres psql
buyrug'ini berish yetarli.create database dbnomi;
create user dbuser with encrypted password 'parol123';
grant all privileges on database dbnomi to dbuser;
GRANTED
deb tasdiqlaydibrew install heroku/brew/heroku
sudo snap install heroku --classic
heroku login
heroku create proyekt_nomi
git add -A git commit -am "Initial" git push heroku masterMana endi sizning loyihangiz Herokuga yuklandi. Endi navbat keyingi bosqichga ))
heroku addons:create heroku-postgresql:hobby-dev --app PROYEKT_NOMIBu yerda PROYEKT_NOMI o'rniga boshida heroku uchun yaratgan PROYEKT_NOMI ni yozing
heroku run python manage.py collectstatic heroku run python manage.py makemigrations heroku run python manage.py migrate heroku run python manage.py createsuperuser heroku open # brauzerni ochadi.
heroku run python manage.py collectstatic
qilganda chiqadigan error. Ushbu ketma-ketliklarni bajaring:
heroku config:set DISABLE_COLLECTSTATIC=1
git push heroku master
heroku run python manage.py collectstatic