Ultimate Django Deployment on Heroku

Autor: John Cohen

Hi all, Because PI's from our company like Python/Django, we had to deploy our parking app on Heroku. In order to do that, I did a lot of search so, only 2 articles had the info that we needed to do that. One [from codingforentrepreneurs][1]. The second one was from the blog of Vitor Freitas, [simpleisbetterthancomplex.][2] Both of them complete each other, but a beginner needs to have all of the steps out there. Both articles are incomplete, just because they are old. So here we go. This is how my project structure looks like. <img src="https://preview.ibb.co/fd3PYe/1.png" alt="1" border="0" class="img-fluid"> 1. Go to your father folder: `cd Desktop/chn_parcare/` In our situation chn_parcare is our main folder. <img src="https://image.ibb.co/mX54Ye/2.png" alt="2" border="0" class="img-fluid"> 2. Do a `git init` <img src="https://image.ibb.co/gRCtte/3.png" alt="3" border="0" class="img-fluid"> 3. `cd src` and `git init` . Now you are in the source folder of your project. Into this folder there is also manage.py <img src="https://image.ibb.co/gkYSKK/4.png" alt="4" border="0" class="img-fluid"> <img src="https://image.ibb.co/hm6uYe/5.png" alt="5" border="0" class="img-fluid"> 4. Go to Heroku and [SignUp][3] and then install the [CLI.][4] 5. In your terminal `heroku login` 6. Create `.gitignore` and `Procfile` echo ".py[cod]" > .gitignore echo "web: gunicorn chn_parking.wsgi" > Procfile python3 -V 7. Ok! now there is a need of python3 -V to know the right version of python that needs to be installed on Heroku. Therefore there is still a need of creating another file. On the terminal type: `echo "3.7.0" > runtime.txt` <img src="https://image.ibb.co/nGCezK/8.png" alt="8" border="0" class="img-fluid"> 8. Now go back to your src folder `cd ..` and activate virtual environment `source bin/activate` and install Whitenoise `pip install whitenoise`. <img src="https://image.ibb.co/eShCKK/9.png" alt="9" border="0" class="img-fluid"> 9. Now go back to the src folder `cd src` and do `pip freeze > requirements.txt`. We need this just because Heroku has to know what libraries you need in order to run your site. <img src="https://image.ibb.co/ha3ite/10.png" alt="10" border="0" class="img-fluid"> These are my requirements: certifi==2018.8.24 chardet==3.0.4 Click==7.0 decorator==4.3.0 djadmin==1.1.6 Django==2.1.2 django-sql-explorer==1.1.2 future==0.16.0 geocoder==1.38.1 idna==2.7 pytz==2018.5 ratelim==0.1.6 requests==2.19.1 six==1.11.0 sqlparse==0.2.4 ua-parser==0.8.0 unicodecsv==0.14.1 urllib3==1.23 user-agents==1.1.0 whitenoise==4.1 XlsxWriter==1.1.1 10. Now let's move to wsgi.py and add `from whitenoise.django import DjangoWhiteNoise` and `application = DjangoWhiteNoise(application)` <img src="https://preview.ibb.co/kX356z/11.png" alt="11" border="0" class="img-fluid"> 11. Now we have to create the app by giving a name: `heroku create parking-chn`. Our is called parking-chn, you can put a different name 12. To `settings.py` you need to `DEBUG = False` `ALLOWED_HOSTS = ['parking-chn.herokuapp.com, '.herokuapp.com']` Add this to Middleware: `'whitenoise.middleware.WhiteNoiseMiddleware',` <img src="https://image.ibb.co/fkpL6z/12.png" alt="12" border="0" class="img-fluid"> to the DB: import dj_database_url db_from_env = dj_database_url.config() DATABASES['default'].update(db_from_env) DATABASES['default']['CONN_MAX_AGE'] = 500 <img src="https://image.ibb.co/iqAA6z/13.png" alt="13" border="0" class="img-fluid"> Add to the static: `STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'` <img src="https://preview.ibb.co/c6CjYe/14.png" alt="14" border="0" class="img-fluid"> 13. `heroku config:set SECRET_KEY='your pass'` and change the secret key SECRET_KEY = os.environ.get( 'SECRET_KEY', 'my key') <img src="https://image.ibb.co/i624zK/16.png" alt="16" border="0" class="img-fluid"> 14 `pip install django psycopg2 dj-database-url gunicorn` , than `pip freeze > requirements.txt`, than `git add .`, adding the message `git commit -m "Initial Heroku commit` and finally `git push heroku master` 15 Create and migrate the DB `heroku addons:create heroku-postgresql:hobby-dev` and `heroku run python manage.py migrate`, `heroku run python manage.py makemigrations` and `heroku run python manage.py createsuperuser` and finaly `heroku run python manage.py collectstatic`. Now disable collectstatic `heroku config:set DEBUG_COLLECTSTATIC=1` Et voila! <img src="https://preview.ibb.co/gXZy9K/18.png" alt="18" border="0" class="img-fluid"> [1]: https://www.codingforentrepreneurs.com/blog/go-live-with-django-project-and-heroku/ [1]: https://www.codingforentrepreneurs.com/blog/go-live-with-django-project-and-heroku/ [2]: https://simpleisbetterthancomplex.com/tutorial/2016/08/09/how-to-deploy-django-applications-on-heroku.html [3]: https://signup.heroku.com [4]: https://devcenter.heroku.com/articles/heroku-cli

Ilfov, Romania
Telefon: 0771.060.860.    
Site: www.cohen.ro 
Email: [email protected]

#detectivparticular #pi #romania #bucuresti #investigatii #it #cybersecurity #detectiv #detectivi #politia #police #inselaciuni #verificari #siguranta #incredere #iubit #iubita #iubire #security #homeprotection #protection #tscm #facialrecognition #recunoasterefaciala #soft #phishing #scams #chatboot #pi #robot #malitious #html #car #carrecognition #bucharest #bucuresti #nato #wearenato #heroku #development #nato #security #cybersecurity #wireless #pentestings #penetrationtesting #personrecognition #indivizi #recunoasterepersoane #video #searex #privatesearch #internet

Pictures Copyright Pozele acestui articol au fost luate de pe site-ul www.pexels.com, site care ofera gratis spre uz personal si comercial aceste poze. --- [All photos on Pexels can be used for free for commercial and noncommercial use](https://www.pexels.com/photo-license)


Any actions and or activities related to the material contained within this Website is solely your responsibility.The misuse of the information in this website can result in criminal charges brought against the persons in question. The authors and Our Company will not be held responsible in the event any criminal charges be brought against any individuals misusing the information in this website to break the law.

This site contains materials that can be potentially damaging or dangerous. If you do not fully understand something on this site, then GO OUT OF HERE! Refer to the laws in your province/country before accessing, using,or in any other way utilizing these materials.These materials are for educational and research purposes only! Do not attempt to violate the law with anything contained here. If this is your intention, then LEAVE NOW! Neither administration of this server, the authors of this material, or anyone else affiliated in any way, is going to accept responsibility for your actions. Neither the creator nor Our Company is responsible for the comments posted on this website.

Any linked sites are not under the control of author or Our Company and the author or Our Company is not responsible for the contents of any linked site or any link contained in a linked site, or any changes or updates to such sites. We are providing these links to you only as a convenience, and the inclusion of any link does not imply endorsement by us.

In any site as large as ours that deals with so many controversial topics and skills, it has become necessary to address a few incidents and implement a user terms and services agreement. We want to provide a free, safe and legal training environment to the users of this site.

Our Aim

Our Company : This website will help you gain entry into the minds of seasoned computer criminals, so that you can forestall their attempts and you will be hence well equipped to detect the ways in which hackers can infiltrate your system.

Your usage of this website constitutes your agreement to the following terms.

  1. All the information provided on this site are for educational purposes only. The site is no way responsible for any misuse of the information.
  2. Our Company is a site related to Private Investigation and not a site that promotes hacking /cracking / software piracy.
  3. This site is totally meant for providing information on "Private Investigation", “Computer Security”, “Computer Programming” and other related topics and is no way related towards the terms “CRACKING” or“HACKING” (Unethical).
  4. Few articles (posts) on this site may contain the information related to “Hacking Passwords” or“Hacking Email Accounts” (Or Similar terms). These are not the GUIDES of Hacking. They only provide information about the legal ways of retrieving the passwords. You shall not misuse the information to gain unauthorised access. However you may try out these hacks on your own computer at your own risk. Performing these attempts (without permission) on computers that you do not own is illegal.
  5. The virus creation section on this site provides demonstration on coding simple viruses using high level programming languages. These viruses are simple ones and cause no serious damage to the computer. However we strongly insist that these information shall only be used to expand programming knowledge and not for causing malicious attacks.
  6. All the information on this site are meant for developing Defense attitude among the users and help preventing the hack attacks. Our Company insists that these information shall not be used for causing any kind of damage directly or indirectly. However you may try these codes on your own computer at your own risk.
  7. The word “Hack” or “Hacking” that is used on this site shall be regarded as “Ethical Hack” or “Ethical Hacking” respectively.
  8. We believe only in White Hat Hacking. On the other hand we condemn Black Hat Hacking.
  9. Some of the tricks provided by us may no longer work due to fixture in the bugs that enabled the exploits. We are not responsible for any direct or indirect damage caused due to the usage of the hacks provided on this site.
  10. We reserve the right to modify the Disclaimer at any time without notice.
  11. We are not the vendors of any products (software, books etc.) that we recommend on our website in the PRODUCTS section and other selected posts/articles. Hence we do not have any liability related to the products recommend by us. It is the responsibility of the buyers to contact the respective vendors for any queries related to the products.