学生向けプログラミング入門 | 無料

学生向けにプログラミングを無料で解説。Java、C++、Ruby、PHP、データベース、Ruby on Rails, Python, Django

Django3.2 | クラウドソーシングアプリの構築 | 60 | Heroku Redis

↓↓クリックして頂けると励みになります。


59 | Heroku デプロイ】 << 【ホーム


Herokuでデプロイしたアプリを開き、「Configure Add-ons」をクリックします。

Configure Add-ons
Configure Add-ons



アドオンを検索し、「Heroku Data for Redis®*」を選択します。

Heroku Data for Redis®*
Heroku Data for Redis®*



一番安い月$3を選択し、オーダーします。

月最大3$
月最大3$



処理中のマークが消えれば準備完了です。

処理中
処理中
準備完了
準備完了



Redisをクリックします。

Redisを選択
Redisを選択



「Settings」タブの「View Credentials…」をクリックします。

View Credentials…
View Credentials…



View Credentials…に書かれているデータベースの内容を登録します。

View Credentials…
View Credentials…



「crowdsource/settings.py」ファイルを編集します。
「hosts」にRedisのURLを貼り付けます。


記述編集 【crowdsource/settings.py】183行目

# Channels
CHANNEL_LAYERS = {
    'default': {
        'BACKEND': 'channels_redis.core.RedisChannelLayer',
        'CONFIG': {
            "hosts": ['rediss://:p5ee75e39a3abbee9585f4c13e8ce814ad814573e8b32de1d4b2e6ade87214ea4@ec2-54-208-184-71.compute-1.amazonaws.com:13690'],
        },
    },
}



「crowdsource/asgi.py」ファイルを編集します。


記述編集 【Desktop/crowdsource/crowdsource/asgi.py】

import os
from django.core.asgi import get_asgi_application

# Fetch Django ASGI application early to ensure AppRegistry is populated
# before importing consumers and AuthMiddlewareStack that may import ORM
# models.
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "crowdsource.settings")
django_asgi_app = get_asgi_application()

from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter

from crowdsource.urls import websocket_urlpatterns

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'crowdsource.settings')

application = ProtocolTypeRouter({
    "http": django_asgi_app,
    "websocket": AuthMiddlewareStack(
      URLRouter(websocket_urlpatterns)
    )
})



「crowdsource/Procfile」ファイルを編集します。


記述編集 【Desktop/crowdsource/Procfile】

web: daphne crowdsource.asgi:application -p $PORT -b 0.0.0.0 -v2



「daphne==3.0.1」をインストールします。
コマンド
pip install daphne==3.0.1


バージョンファイルを出力します。
コマンド
pip3 freeze > requirements.txt


記述編集 【Desktop/crowdsource/requirements.txt】

aioredis==1.3.1
asgiref==3.7.2
async-timeout==4.0.3
attrs==23.1.0
autobahn==23.6.2
Automat==22.10.0
beautifulsoup4==4.12.2
CacheControl==0.13.1
cachetools==5.3.1
certifi==2023.7.22
cffi==1.15.1
channels==3.0.3
channels-redis==3.2.0
chardet==3.0.4
charset-normalizer==3.2.0
constantly==15.1.0
cryptography==41.0.3
daphne==3.0.1
defusedxml==0.7.1
dj-database-url==2.1.0
Django==3.2.20
django-bootstrap4==2.3.1
django-on-heroku==1.1.2
firebase-admin==4.4.0
google-api-core==1.34.0
google-api-python-client==2.97.0
google-auth==2.22.0
google-auth-httplib2==0.1.0
google-cloud-core==2.3.3
google-cloud-firestore==2.11.1
google-cloud-storage==2.10.0
google-crc32c==1.5.0
google-resumable-media==2.5.0
googleapis-common-protos==1.60.0
grpcio==1.57.0
grpcio-status==1.48.2
gunicorn==20.0.4
hiredis==2.2.3
httplib2==0.22.0
hyperlink==21.0.0
idna==2.10
incremental==22.10.0
msgpack==1.0.5
oauthlib==3.2.2
paypalrestsdk==1.13.1
Pillow==10.0.0
proto-plus==1.22.3
protobuf==3.20.3
psycopg2-binary==2.9.7
pyasn1==0.5.0
pyasn1-modules==0.3.0
pycparser==2.21
PyJWT==2.8.0
pyOpenSSL==23.2.0
pyparsing==3.1.1
python3-openid==3.2.0
pytz==2023.3
requests==2.25.0
requests-oauthlib==1.3.1
rsa==4.9
service-identity==23.1.0
six==1.16.0
social-auth-app-django==4.0.0
social-auth-core==4.4.2
soupsieve==2.5
sqlparse==0.4.4
stripe==2.55.1
Twisted==23.8.0
txaio==23.1.1
typing_extensions==4.7.1
uritemplate==4.1.1
urllib3==1.26.16
whitenoise==6.5.0
zope.interface==6.0



Githubに変更をコミットします。

Githubにコミット
Githubにコミット



Githubにプッシュします。
コマンド
git push heroku main


アプリケーションの動作を確認してください。

アプリケーションの動作確認
アプリケーションの動作確認