Django: Testing locally before pushing app to Heroku - django

I've followed the instructions from Heroku's "Getting Started with Django", and successfully deployed my application on the Heroku server.
However, there wasn't any tutorial on how to test my application locally before committing and pushing any change on my codes. For example, after I make some minor changes on my css file or Django views, I want to test it on my local computer first, instead of having to do "git push heroku master" every time..
How do I do this with Heroku?
Thanks

To test your app locally you don't need to use Heroku. Simply go to the folder where your manage.py is and do:
python manage.py runserver
It will fire up a development web server with your app you can access using the following URL in your browser: http://localhost:8000.
This web server reloads automatically when you make changes to the Python code. See the Django tutorial: https://docs.djangoproject.com/en/1.7/intro/tutorial01/#the-development-server
Additionally, you might need to set some variables in your environment (export VARNAME=value) to make it work with 12-factor-style settings.

Related

How do I recommit database to Heroku after destroying DB in the Heroku dashboard

I've built an app using Django etc. I ran into a whole bunch of problems with database on Heroku after accidentally pushing to production before running heroku run python manage.py makemigrations and heroku run python manage.py migrate.
I decided to just completely destroy the database currently on Heroku and want to recommit my app's models to heroku. My hope is to completely start from a clean slate.
I just want to make sure I do this correctly so I'm asking for clear instructions about how to recommit my app's database to Heroku after destroying the database in the dashboard.
Current error I get when I open my app online is:
settings.DATABASES is improperly configured. Please supply the NAME or OPTIONS['service'] value.
Thanks!
If you completely removed your database you'll have to provision another one. Assuming you are using Heroku Postgres¹, you can do that using the Heroku CLI like so:
heroku addons:create heroku-postgresql:hobby-dev
Here we are asking Heroku to provision the heroku-postgresql add-on using the free hobby-dev tier. Modify as needed.
You can also provision add-ons using the Dashboard if you prefer.
As part of the provisioning process, Heroku Postgres will automatically set a new DATABASE_URL for your app. As long as your project was using this variable before you deleted your old database, it should find the new database without requiring any changes.
¹If you were using a different database add-on the solution should be more or less the same. Provision a new instance of the add-on, let it set its environment variable, and if your app was using that variable before it should pick it up on its own.

Heroku set default site

I have created a new Heroku site and I am developing it on my Linux box, using Django. The standard "getting started" site Heroku created for me is called "gettingstarted". How can I change that / configure Heroku to forget about it?
I was reading through the Django tutorial, which explains how to create a new site (django-admin startproject my_site). I did this successfully for a demo project. Then I tried to do it under the Heroku directory, because I wanted a better name for my site than "gettingstarted". I noticed that every time I start the Heroku server under my project, it says ...using settings 'gettingstarted.settings'. I found that this is configured in manage.py and I change it.
This is the directory layout I have
/some/path/heroku_random_name/gettingstarted/settings.py
/some/path/heroku_random_name/my_site/settings.py
/some/path/heroku_random_name/my_app
This is what I have in
/some/path/heroku_random_name/manage.py
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'my_site.settings')
so I would expect that the site that matters is my_site.
I got it to the point where I can run the site successfully on my local machine, and I can tell that it using the settings from my_site. But when I deploy the project to Heroku, it does not recognize my_app until I register it in gettingstarted/settings.py. In other words, when running in Heroku, it is still using gettingstarted as the site to run.
I am new to all this, so I left gettingstarted in the project, because I am afraid to break things. But how can I configure Heroku to execute settings from my_site and not from gettingstarted?
Found it: it's configured in Procfile.
It's confusing because it's configured in one place for running locally and in a different place for running hosted at Heroku.

Deploying Django App on Heroku using Windows

I want to deploy my django app on heroku , which I have built on Windows machine.
Can I deploy the same application using heroku toolbelt for windows.
Or I have to setup all the things on a unix machine.
And one more thing the application uses Python 3 and Django 1.8
Will that be any problem.
There aren't any special process listed in the docs for windows usersYou should actually deploy from a unix environment, you have to create your Procfile, requirements.txt and make some changes to your settings.py file, it's easy and straight forward.
A step by step guide can be found here https://devcenter.heroku.com/articles/getting-started-with-django
Some problems you may encouter:
Internal Server Error heroku/django
Django migrations fail in heroku
Also make sure you add your migrations and cache folders to your .gitignore file.

Two Heroku Apps for the Same Project?

I currently have a django project deployed on Heroku, but I would like to deploy another dummy Heroku app for testing purposes. The idea is that I can make changes to the dummy Heroku account on a git branch, see how it works live, and then merge and push to my actual Heroku project. Is this possible?
I haven't tried this but I don't see why it wouldn't be possible.
Just add another remote on git to the repository to your production heroku git address.
git remote add htest your_test_app_heroku.git
git remote add heroku your_actual_app_heroku.git

Template not found with Django on Heroku

Developing a Django app and decided to ditch the Linode for Heroku. Just too much crap to deal with. So I can run my app fine using python manage.py runserver both locally and when ssh'd into the Linode, but when pushed to the heroku git repo (goes through, runs fine), I get TemplateDoesNotExist at / home.html. On my computer the folder is located at Heroku/Django_App/OmniCloud_App/Templates/ (Django_App is the folder with settings.py, etc.).
Heroku is checking at /app/OmniCloud_App/Templates/ How can I see the file structure of Heroku and specify that in settings.py so I can run the app locally for development as well as pushed to Heroku?
Once you've pushed to heroku you may connect to an isolated instance of your heroku app through bash. You can access this with:
heroku run bash --app appname
(Keep in mind this does use hours off of your heroku credit though).