Django deployment on heroku not working - django

I created a personal portfolio website for myself using django and it also includes a blog. You can see the exact directory listing and source code in my github repository by clicking here
I have the procfile and the requirements.txt file as said in the heroku website and did the following in command prompt as directed by heroku :
$ heroku login
$ heroku git:clone -a appname
$ cd appname
$ git add .
$ git commit -am "make it better"
Then collectstatic --noinput error occurred so I did this:
heroku config:set DISABLE_COLLECTSTATIC=1
Then I again repeated the deployment process and this time the deployment was successfull. And then I opened the app but the website did not appear. Instead this appeared.
Please help me deploy this website.

You are probably developing on Windows. Heroku, like most deployment environments, uses Linux; in that environment the file system is case-sensitive. Your Templates directory should be called "templates".
Please note also you should not be committing a lot of this stuff to either Github or Heroku. In particular the venv directory at the base level, and the pycache directories inside each directory, should be excluded. You can use the git exclude functionality to ensure they are not added.
Also it is very strange that you have named your templates with ".php" extensions. There is no PHP involved here.

Related

Can I download source code which has deployed with github from Heroku?

I have deployed my django-app on heroku with Github.
It is test server so I am using sqlitedb.
But because of the dyno manager, my sqlitedb resets everyday.
So I am going to download only db on heroku.
I tried this command.
heroku git:clone -a APP-NAME
But this clones empty repository.
And when I run $heroku run bash -a APP-NAME command, I got ETIMEOUT error.
Is there any other way to download the source code on heroku?
What you want to do with git is not possible because changes to the database is not versioned.
The command to run bash on Heroku is heroku run bash, not heroku bash run. You may have to specify the app using the -a flag: https://devcenter.heroku.com/articles/heroku-cli-commands#heroku-run
I have solved with downloading the application slug.
If you have not used git to deploy your application, or using heroku git:clone has only created an empty repository, you can download the slug that was build when you application was last deployed.
First, install the heroku-slugs CLI plugin with heroku plugins:install heroku-slugs,
then run:
heroku slugs:download -a APP_NAME
This will download and compress your slug into a directory with the same name as your application.

Django Heroku : python: can't open file 'manage.py': [Errno 2] No such file or directory

I am deploying a Django website on Heroku. My project is called mysite-project which contains at its root manage.py and Procfile
I can visit the heroku website after I run git push heroku master.
And the website shows:
I am assuming I do not see anything (navbar, initial page, etc.) because I did not run migrate.
If I do:
heroku run python manage.py migrate
I get the error:
python: can't open file 'manage.py': [Errno 2] No such file or directory
Which makes no sense since I am in the right directory.
In fact:
I can run python manage.py runserver and locahost works
git ls-files manage.py --outputs--> manage.py
BUT
If I do:
heroku run bash
ls manage.py
I get:
ls: cannot access 'manage.py': No such file or directory
It seems that manage.py is in my local but not in my heroku.
Procfile
web: gunicorn mysite-project.wsgi
First use heroku logs --source app --tail to make sure that the Build succeeded.
If the build is successful, make sure you have your project at the root of the git repo.
I had the same problem because my Django project was not at the root of the git repo.
My file hierarchy was first like (assuming the name of the project prototype and it has one app named app)
├──git_repo
        ├──Procfile
        ├──requirements.txt
        ├──new_folder
                ├──prototype (folder)
                ├──app (folder)
                ├──.gitignore
                ├──manage.py
                ├──db.sqlite3
I changed the hierarchy to the following and it worked
├──git_repo
        ├──Procfile
        ├──requirements.txt
        ├──prototype (folder)
        ├──app (folder)
        ├──.gitignore
        ├──manage.py
        ├──db.sqlite3
The welcome you see when you visit the site (as well as the fact, that you can't find manage.py with ls on the server) tells you, that you haven't successfully pushed your django project to Heroku yet. Try and run git push heroku master.
It may be that the push has failed, in which case you should consult the documentation. Specifically, run
$ pip install gunicorn django-heroku
$ pip freeze > requirements.txt
...and then add
import django_heroku
django_heroku.settings(locals())
...to the bottom of settings.py. Also don't forget to set STATIC_ROOT='staticfiles' in settings.pyaswell.
That screenshot attached indicates you have just created app in heroku but not pushed your local repository code to heroku app.
git push heroku master
I was getting this error too!
I solved it by specifying the path:
python <your_project_name>/manage.py migrate
This worked for me.
In my case, it was because I was using a branch name other than master. My branch name was heroku_branch, so to make things work properly, I pushed it this way
git push heroku heroku_branch:master
It was pushed this time and worked fine.
For django + heroku
web: python manage.py runserver 0.0.0.0:\$PORT

How to runserver and see website for github project files

New to Django, I am trying to view the website with its associated functionality generated by the project files here:
https://github.com/tomwalker/django_quiz
When I use the usual: manage.py runserver on the command prompt, it says that there is no manage.py file, and there isn't.
Worryingly, I followed the instructions for installation which suggested: Run pip install -r requirements.txt
...and my computer proceeded to de-install Django 2.0? What is that about, and can anyone explain how to restore settings if I messed them up completely.
The second part of the instructions for installation asks to change something in the INSTALLED_APPS and urls.py section, but where? There is nothing in the root directory and it doesn't specify which folder/app to do this in?
I don't quite understand how to "run" (see/view) these files and see this quiz app in process on my local host. What do I need to add? Why is the manage.py file not included?
Any explanation or something to point me in the right direction would be appreciated
The github project contains only Django apps. Not whole project. You need to integrate this in your Django project. You can run it by following below steps.
Create New Django Project
Clone github repo in your project. Run following commands in your project directory.
git clone https://github.com/tomwalker/django_quiz.git
mv django_quiz/* .
rm -rf django_quiz
Add essay, true_false, quiz, multichoice in your installed apps
Install requirements with pip install -r requirements.txt
Create Migrations
Run Migrations
Add url(r'^q/', include('quiz.urls')) in your project urls.
Run server with python manage.py runserver

Can't find .env file for locally starting Django app using 'heroku local'

I want to local run my Django app with Heroku using, for example, 'heroku local -e .env.test' (see https://devcenter.heroku.com/articles/heroku-local). I am using virtualenvwrapper so my envs (test, dev) are not in my Django project server but located in my $WORKON_HOME directory. I don't know what to specify for the last part of the command because I can't find the .env files in the $WORKON_HOME.
I've tried heroku local -e $WORKON_HOME/dev and heroku local -e $VIRTUAL_ENV and get the same error: ▸ EISDIR: EISDIR: illegal operation on a directory, read
For me, the problem was that I had created a virtualenv directory called .env, conflicting with Heroku's ENV system which uses the same filename. Deleting the virtualenv and recreating it as .venv solved my problem:
deactivate
rm -rf .env
virtualenv .venv
source .venv/bin/activate
NB. You can't just rename the .env directory without having to manually edit the virtualenv configuration too; better just to destroy and recreate.
I think the confusion comes from what you think .env does: that is used by the Procfile (which is called by Foreman https://ddollar.github.io/foreman/ ) to set environment variables like:
A=b
C=d
.env there is not your virtualenv, which you should not git track.
Just use your virtualenv as usual before calling heroku local and track a requirements.txt (and possibly runtime.txt for the Python version, see https://devcenter.heroku.com/articles/deploying-python )
Heroku will automatically use virtualenv when you push.
As usual, look for minimal working examples to get started: https://github.com/heroku/heroku-django-template
Answering my own question:
I was able to solve my issue by issuing the following command from the base directory of my Django project.
echo "source /home/your_username/.virtualenvs/venv_name_here/bin/activate" >> .env
[the command is referenced here: How to create/make your app LOCAL with Heroku/Virtualenv/Django? ]
Reiterating, this was needed because virtualenvwrapper doesn't automatically create .env's. Thus,heroku local's apparent need for a .env requires a manual creation of the environmental file. #ciro-santilli-巴拿馬文件-六四事件-法轮功 if you know a better way, such as some option of heroku local, I'd like to know.

django - deploy project to heroku

I have an django project (RESTful API written using Django Rest Framework) which uses the Postgres database.
I have a local git repository of the project and also I have it on my github account, and I want to deploy the porject to heroku.
In the official heroku tutorials, they don't show anything about how to prepare your app to deployment - (requirements file, settings file, Proc File, maybe more stuff that I don't know - which I saw in different tutorials that you need to do).
At the moment I only have the django app without any added file.
My question is - what do I need to do to prepare my app to deployment to heroku? as I said at the moment I have a local git repository and its also on Github.
Thanks!
1) Create a file called Procfile (no extension) in your project root with the following inside:
web: gunicorn APP_NAME.wsgi (replace APP_NAME with your app's name).
2) Pip install gunicorn and dj-database-url
3) In your virtual env terminal, run pip freeze > requirements.txt in your project root (do this every time you pip install any new packages).
4) In your production settings file, add the following to make your database work on heroku:
import dj_database_url
DATABASES['default'] = dj_database_url.config()
Note: This will cause errors in your local environment, so make sure you have a prod.py settings file as well (ask if you need an explanation).
5) Add heroku to your git settings via git remote add heroku git#heroku.com:HEROKU_APP_NAME.git (replace HEROKU_APP_NAME with your Heroku app name).
6) Once you do git add --all, git commit -m "SOME MESSAGE HERE" and git push, you can do git push heroku master.