Use Heroku to build Django apps

Source: Internet
Author: User
Tags virtual environment heroku toolbelt

Heroku to Django support is good, although no pythonanywhere as simple as to a shell casually toss, the key function is also no less.

Main references:
Official document Getting Started with Django on Heroku
How to deploy the Django app to Heroku?

Register login What do not say, to pay attention to a few places, one can not use 163 mailbox, the reason I am not very clear, the second is to use Heroku and git off the relationship, I personally think the mailbox here is the best is also and git binding.
The first thing to look at is getting started with Python is not Django, but the example it gives is a Django project, so let's take a look at this example.

Installing Heroku Toolbelt

trouble thing = = Why OpenShift and this all want to install what can transmit, circumnavigated pythonanywhere convenient dead.
When installing, if you already have git on your computer, you don't have to select Full install, choose Custom Install and then cancel git and ssh.
There is a hole in the document written in CMD using Heroku login, but there is no egg, read a blog to know to use git bash open ...

Example

I went through the document process to get a sample app, where the creation of the app is done with the Heroku instructions, almost a local file and app in some way to connect and then synchronize the code. That's probably the process.

    1. Heroku Login login, here the account password I have and git confused ...
    2. git clone https://github.com/heroku/python-getting-started.git here just clone a sample down to do the demo, The next operation will be performed in the Clone folder.
    3. Heroku Create an app, you can take the parameters to specify the app name, do not pick up a random one, this step will generate a warehouse https://git.heroku.com/app-name.git, And then this warehouse is linked to the folder that was just clone down.
    4. git push Heroku master to push this sample app folder to the remote repository you just created, this step will have a lot of output, because in the remote to the requirement.txt inside all installed, there will be a hint.
    5. heroku Open this command appears to be opening the browser to access this page →_→
Deploy your own Apps

Some of the instructions in the document are not necessary, such as the local virtual environment, and so on, in fact, the key to this deployment process is the remote code base link, I here is the case I have a ready-made local app, to hang it up, on the site I have created an app, and now I want to link up the two.

The steps are clear, but there are some details that require some configuration files in this app's folder.

Configuration file

Notice that there are some configuration files in the folder of the previous example

Procfile
web: gunicorn Sample_Project.wsgi --log-file -

Specifically what the meaning is not clear, but to change the sample-project to their own app folder name, the specific is loaded with wsgi.py this file folder name.

Procfile.windows
web: python manage.py runserver 0.0.0.0:5000

The instructions are understood, but they still don't understand what it's about.

Requirement.txt
dj-database-url==0.3.0Django==1.8.1django-postgrespool==0.3.0gunicorn==19.3.0psycopg2==2.6SQLAlchemy==1.0.4whitenoise==1.0.6

Projects need to install the kit, in their own projects as needed to modify the line.

Runtime.txt
python-2.7.9

Python version, the amount is also copied directly over.

Warehouse Links

Need to add a remote link to the local repository of the Heroku app warehouse, do not want to confuse with the previous so copied the folder, changed a name, the. git folder deleted.

Then, according to the above process operation completed, access.
It can be accessed, but the database is not synced in the past. Access to the page is a database can not find the problem, and then go to Baidu Database processing.

Database configuration

My App folder has a Sqlite3 db file, but complete wood is useful ... In Heroku there should be some other way to use the database, which requires several steps.

settings.py
import dj_database_urlDATABASES[‘default‘] = dj_database_url.config()

Add the following section of the database configuration.

Build Database

Then it's still working in Git bash and running after the code has been updated:

heroku run python manage.py makemigrationsheroku run python manage.py migrate

There's no problem with that.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Use Heroku to build Django apps

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.