1. Trang chủ
  2. » Công Nghệ Thông Tin

Hướng dẫn deploy Django Web bằng Heroku

27 350 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Cấu trúc

  • I. Configure a Cloud Computing platform with a cloud service provider’s framework.

  • II. Implement a cloud platform using open source tools

Nội dung

Hướng dẫn chi tiết cách để đưa trang web từ local host lên mạng internet thông qua Heroku.Yêu cầu bạn có chút kiến thức về Django, python.Hướng dẫn này sẽ giúp bạn thực hiện host web django.Nếu có khó khăn liên hệ mình qua email: cuonglieu3256gmail.com

DEPLOY DJANGO IN HEROKU Configure a Cloud Computing platform with a cloud service provider’s I framework A Git  Sign in Github Create account github or sign up if you are beginer in github Figure GIt Login page  After registration or login successfully, you will be directed to the main page of git hub, if you are new, the following will be displayed: DEPLOY DJANGO IN HEROKU Figure Home page with beginer  And if you are an old user, the display is as follows  Create your repositories Find block content of repostpries with NEW button DEPLOY DJANGO IN HEROKU Figure New Repositories  Enter the information of repositories Figure Information of New Repositories  Click button to create repositories  You then have repositories to store DEPLOY DJANGO IN HEROKU Figure ATN Repositories B Heroku Sign up Heroku Figure Sign up Heroku DEPLOY DJANGO IN HEROKU  Register with your personal information and click create account, click button free account Figure Create Free Account  Confirm email for sign up Heroku Web send you email to confirm Figure Confirm Email  Open the Gmail or Mail Software to read the new email and click link to confirm DEPLOY DJANGO IN HEROKU Figure Link to confirm email  Set up password When you click on the confirmation link, you will be redirected to a page to set a password for your account DEPLOY DJANGO IN HEROKU Figure 10 Setup Password  You must set the above eligible accounts: for example Khoa @ 12345 DEPLOY DJANGO IN HEROKU Figure 11 Enter information of password  Proceed to Heroku When the setup is successful, the password will go to the link page, click the button to go to the Heroku dashboard Figure 12 Web Link to Dashboard DEPLOY DJANGO IN HEROKU o Click button to Dashboard Figure 13 Button to Proceed  Homepage of Heroku Figure 14 Homepage of Heroku C Connect Heroku to Git  Create new app On the Heroku homepage, select create new app, to create a new app to deploy to heroku Figure 15 Create new app on Heroku DEPLOY DJANGO IN HEROKU  Enter information about App and click button Create App Figure 16 Information app  Create successfully, will appear in the homepage Figure 17 Homepage with app  Connect Git on Heroku Click Icon App on Heroku page DEPLOY DJANGO IN HEROKU Figure 23 Connect Succes Heroku and GIthub D PostgreSQL on Heroku Choose the App for Create PostgreSQL Figure 24 Choose App for PostgreSQL  Add a PostgreSQL Database To attach a PostgreSQL database to the app you just created, you need to navigate to the Resources tab in the header of your newly created app's dahsboard Then type Heroku Postgres into the Add-ons search field Figure 25 Resources Heroku DEPLOY DJANGO IN HEROKU  When shown, select the suggested Heroku Postgres add-on from the dropdown: Figure 26 Heroku PostgreSQL  The next popup asks you to choose a pricing plan for the database Select the Hobby Dev - Free plan and click Provision: Figure 27 Heroku Platform Free  Create PostgreSQL Success Figure 28 Heroku Success DEPLOY DJANGO IN HEROKU  Access the database credentials and connect To find the credentials and the connection URL for the PostgreSQL database, you need to navigate to the Resources tab in your app's dashboard again and select the Heroku Postgres resource: Figure 29 PostgreSQL Dashboard  Now select the Settings tab in the header of that screen: Figure 30 Setting PostgreSQL Heroku  Here, you can click the View Credentials button to see the credentials of your PostgreSQL database: DEPLOY DJANGO IN HEROKU Figure 31 Credentials of PostgreSQL  You can use these credentials to connect to your PostgreSQL database from any PostgreSQL client, e.g psql (CLI), TablePlus or Postico (GUIs II Implement a cloud platform using open source tools A PgAdmin Database for ATN  Installing Postgres/pgAdmin locally If you don’t have postgres locally, download it along with pgAdmin: https://www.postgresql.org/download/ Figure 32 Dowload PostgreSQL  As stated on the downloads page, the installer should include pgAdmin (among various other clients) Ensure that this is the case and that these options are checked during installation  It’s easy to verify if postgres exists by simply just running one of the clients createdb version DEPLOY DJANGO IN HEROKU  If for some reason you have postgres installed but not pgAdmin, you can add it separately: https://www.pgadmin.org/download/ Figure 33 PgAdmin Dowload  Accessing Remote Databases Locally Add new server to connect Heroku SQL with PgAdmin4 Figure 34 Add new Server  Choose Connection and enter information Heroku SQL o My information DEPLOY DJANGO IN HEROKU Figure 35 Information Heroku SQL o Then Enter information , click save to create server with Database Figure 36 Connect Database  Click Database , and click ctrl + F , to find your database in PgAdmin Server DEPLOY DJANGO IN HEROKU Figure 37 Find server  Then find server successly , you will all with database and Heroku SQL will restart Example : Insert new data : o First , Check your my data Figure 38 Check PostgreSQL o Secoud,Check your heroku SQL , If all the data are the same, then the database is connected DEPLOY DJANGO IN HEROKU Figure 39 Check PostgreSQL in Heroku B Development ATN interfaces  Install Package and Setup envinorment Create folder ATN for new project Figure 40 ATN Folder  Open ATN Store Folder in VS Code DEPLOY DJANGO IN HEROKU Figure 41 Terminal ATN in VS Code  Open terminal, Create Virtual Envinorment Python in folder Figure 42 Create venv  From within VS Code, select a Python interpreter by opening the Command Palette (Ctrl+Shift+P), start typing the Python: Select Interpreter command to search, then select the command You can also use the Select Python Environment option on the Status Bar if available (it may already show a selected interpreter, too): Figure 43 Select Python Interpreter DEPLOY DJANGO IN HEROKU  Choose python venv in folder Figure 44 venv Python  Run Terminal: Create New Integrated Terminal (Ctrl+Shift+`) from the Command Palette, which creates a terminal and automatically activates the virtual environment by running its activation script Figure 45 Active Venv  Install Django and package Figure 46 Install Package  After downloading successfully, you learn how to develop an app with django  Read the documentation here: https://docs.djangoproject.com/en/2.1/intro/tutorial01/  Development ATN web in Local Host When you read Document and start App by Django o Set up Environment pip install django django-filter django-storages boto3 pillow gunicorn whitenoise django-heroku djdatabase-url psycopg2 DEPLOY DJANGO IN HEROKU o Setings.py in Django , find the dulicate settings in settings.py and change DEBUG = False #new ALLOWED_HOSTS = [‘geneticabook.herokuapp.com','127.0.0.1'] #new 'whitenoise.middleware.WhiteNoiseMiddleware',#new STATICFILES_STORAGE = 'whitenoise.storage.CompressedStaticFilesStorage' STATIC_ROOT = os.path.join(BASE_DIR,'staticfiles') MEDIA_URL ='/media/' MEDIA_ROOT = os.path.join(BASE_DIR,'media')  Settings Database by User Name in Heroku Figure 47 Settings Database in Django Connect Heroku SQL  Create Procfile file without txt: this file will call wsgi of django to let heroku know which file to run first, simply understand it so that it can run the command python manage.py runserver Without this file, the system will not know which file to run first web: gunicorn .wsgi log-file  Create runtime.txt file this will select the python version for heroku to run python-3.8.1 C Commit your code to git DEPLOY DJANGO IN HEROKU  Connect Github Open terminal in project , run git init Figure 48 Create git in folder  Create README.md Figure 49 Add Readme.md  Add File to GitHub Figure 50 Add all file in git  Commit add file to github Figure 51 Commit github  Remote project Github Figure 52 Remote project Github  Push Code to GitHub DEPLOY DJANGO IN HEROKU Figure 53 Push Code to GitHUb Check github Figure 54 Check GitHub D Deploy your app on Heroku  Enable Automatic Deploys Click Enable automatic deploys DEPLOY DJANGO IN HEROKU Figure 55 Enable Automatic  Enable Automatic Deploys success , if you don’t want Automatic , click again Figure 56 Automatic Deploys Success  Deploy apps Choose the branches from github , I choose master and click Deploy Branch Figure 57 Choose the Branches  Deploy processs DEPLOY DJANGO IN HEROKU Figure 58 Deploy Process  Deploys Successfully then click View App Figure 59 View App then Deployed Success  View App in Web https://geneticabook.herokuapp.com/ Figure 60 App in Web ... repositories  You then have repositories to store DEPLOY DJANGO IN HEROKU Figure ATN Repositories B Heroku Sign up Heroku Figure Sign up Heroku DEPLOY DJANGO IN HEROKU  Register with your personal information... with app  Connect Git on Heroku Click Icon App on Heroku page DEPLOY DJANGO IN HEROKU Figure 18 Heroku ATN App  In Dashboard Choose Deploy With Github Figure 19 Deploy Heroku  Connect to Github... GitHub DEPLOY DJANGO IN HEROKU Figure 53 Push Code to GitHUb Check github Figure 54 Check GitHub D Deploy your app on Heroku  Enable Automatic Deploys Click Enable automatic deploys DEPLOY DJANGO

Ngày đăng: 10/08/2020, 16:14

TỪ KHÓA LIÊN QUAN

w