I am trying deploy my assets files to heroku and I get this output in my command line interface:
(nrb_dev) ➜ neurorehabilitation_projects git:(master) ✗ heroku run python manage.py collectstatic
Running python manage.py collectstatic on neurorehabilitation.... up, run.5168
python: can't open file 'manage.py': [Errno 2] No such file or directory
(nrb_dev) ➜ neurorehabilitation_projects git:(master) ✗
It's strange for me, due to I am currently in the directory/folder in which the manage.py
file is located
With the order to get an application early deployment, I've choose disable the environment variable DISABLE_COLLECT_STATIC
of this way:
(nrb_dev) ➜ neurorehabilitation_projects git:(master) ✗ heroku config:set DISABLE_COLLECTSTATIC=1
Setting config vars and restarting neurorehabilitation... done
DISABLE_COLLECTSTATIC: 1
(nrb_dev) ➜ neurorehabilitation_projects git:(master)
According to the above, when I perform git push heroku master
I can deploy mi application:
remote:
remote:
remote: -----> Discovering process types
remote: Procfile declares types -> web
remote:
remote: -----> Compressing...
remote: Done: 46M
remote: -----> Launching...
remote: Released v15
remote: https://neurorehabilitation.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/neurorehabilitation.git
* [new branch] master -> master
(nrb_dev) ➜ neurorehabilitation_projects git:(master) ✗
According to the previous actions, in my main link https://neurorehabilitation.herokuapp.com/ there is an error, I guess that it's because the static files des not were sent and were disabled.
Is this right? I don't know ...
But, something that seem strange is that in my Django Admin https://neurorehabilitation.herokuapp.com/admin/ I can detail the template and the css styles and js in the admin, then, I unknown if heroku is working with static files or not.
What happened here int this situation with my static files?
However, I follow my process, and in this opportunity I can deploy remotely to heroku actions related with the manage.py
commands.
I've checked this because I can execute my migrations of my application:
(nrb_dev) ➜ neurorehabilitation_projects git:(master) ✗ heroku run python manage.py migrate
Running python manage.py migrate on neurorehabilitation.... up, run.7836
Operations to perform:
Apply all migrations: contenttypes, auth, userprofiles, sessions, medical_encounter_information, admin
Running migrations:
Rendering model states... DONE
Applying contenttypes.0001_initial... OK
Applying contenttypes.0002_remove_content_type_name... OK
Applying auth.0001_initial... OK
Applying auth.0002_alter_permission_name_max_length... OK
Applying auth.0003_alter_user_email_max_length... OK
Applying auth.0004_alter_user_username_opts... OK
Applying auth.0005_alter_user_last_login_null... OK
Applying auth.0006_require_contenttypes_0002... OK
Applying auth.0007_alter_validators_add_error_messages... OK
Applying userprofiles.0001_initial... OK
Applying admin.0001_initial... OK
Applying admin.0002_logentry_remove_auto_add... OK
Applying userprofiles.0002_auto_20160225_2130... OK
Applying userprofiles.0003_auto_20160225_2130... OK
Applying medical_encounter_information.0001_initial... OK
Applying medical_encounter_information.0002_auto_20160225_2130... OK
Applying medical_encounter_information.0003_auto_20160225_2130... OK
Applying medical_encounter_information.0004_auto_20160225_2211... OK
Applying medical_encounter_information.0005_auto_20160225_2211... OK
Applying medical_encounter_information.0006_auto_20160225_2303... OK
Applying medical_encounter_information.0007_auto_20160229_2204... OK
Applying medical_encounter_information.0008_auto_20160229_2208... OK
Applying medical_encounter_information.0009_auto_20160301_0130... OK
Applying medical_encounter_information.0010_auto_20160301_0312... OK
Applying medical_encounter_information.0011_auto_20160301_1525... OK
Applying medical_encounter_information.0012_auto_20160301_1601... OK
Applying medical_encounter_information.0013_auto_20160301_1606... OK
Applying medical_encounter_information.0014_auto_20160301_1629... OK
Applying medical_encounter_information.0015_auto_20160301_1633... OK
Applying medical_encounter_information.0016_auto_20160301_1636... OK
Applying sessions.0001_initial... OK
Applying userprofiles.0004_auto_20160225_2211... OK
Applying userprofiles.0005_auto_20160225_2211... OK
Applying userprofiles.0006_auto_20160225_2303... OK
Applying userprofiles.0007_auto_20160229_2204... OK
Applying userprofiles.0008_auto_20160229_2208... OK
Applying userprofiles.0009_auto_20160301_0130... OK
Applying userprofiles.0010_auto_20160301_0312... OK
Applying userprofiles.0011_auto_20160301_1525... OK
Applying userprofiles.0012_auto_20160301_1601... OK
Applying userprofiles.0013_auto_20160301_1606... OK
Applying userprofiles.0014_auto_20160301_1629... OK
Applying userprofiles.0015_auto_20160301_1633... OK
Applying userprofiles.0016_auto_20160301_1636... OK
(nrb_dev) ➜ neurorehabilitation_projects git:(master)
Also, I ccan create inside my deployed application a superuser from my local toolbet ...
(nrb_dev) ➜ neurorehabilitation_projects git:(master) ✗ heroku run python manage.py createsuperuser
Running python manage.py createsuperuser on neurorehabilitation.... up, run.5381
Username: bgarcial
Email address: bgarcial@sample.com
Password:
Password (again):
Superuser created successfully.
(nrb_dev) ➜ neurorehabilitation_projects git:(master) ✗
After, I've disabled the environment variable setup previously DISABLE_COLLECTSTATIC=1
(I've delete the environment variable from my settings dashboard heroku application)
But, wen I execute again the heroku run python manage.py collectstatic
command, I get this notification:
(nrb_dev) ➜ neurorehabilitation_projects git:(master) ✗ heroku run python manage.py collectstatic
Running python manage.py collectstatic on neurorehabilitation.... up, run.9342
You have requested to collect static files at the destination
location as specified in your settings.
This will overwrite existing files!
Are you sure you want to do this?
Type 'yes' to continue, or 'no' to cancel: yes
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python3.4/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python3.4/site-packages/django/core/management/__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/python/lib/python3.4/site-packages/django/core/management/base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "/app/.heroku/python/lib/python3.4/site-packages/django/core/management/base.py", line 399, in execute
output = self.handle(*args, **options)
File "/app/.heroku/python/lib/python3.4/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 176, in handle
collected = self.collect()
File "/app/.heroku/python/lib/python3.4/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 98, in collect
for path, storage in finder.list(self.ignore_patterns):
File "/app/.heroku/python/lib/python3.4/site-packages/django/contrib/staticfiles/finders.py", line 112, in list
for path in utils.get_files(storage, ignore_patterns):
File "/app/.heroku/python/lib/python3.4/site-packages/django/contrib/staticfiles/utils.py", line 28, in get_files
directories, files = storage.listdir(location)
File "/app/.heroku/python/lib/python3.4/site-packages/django/core/files/storage.py", line 299, in listdir
for entry in os.listdir(path):
FileNotFoundError: [Errno 2] No such file or directory: '/app/neurorehabilitation/settings/static'
(nrb_dev) ➜ neurorehabilitation_projects git:(master) ✗
Checking this inconvenient, I guess that my error is here at the end:
directories, files = storage.listdir(location)
File "/app/.heroku/python/lib/python3.4/site-packages/django/core/files/storage.py", line 299, in listdir
for entry in os.listdir(path):
FileNotFoundError: [Errno 2] No such file or directory: '/app/neurorehabilitation/settings/static'
And, this tell me that in my heroku application deployed does not exist the static
directory
I've executed heroku run bash
for check the structure directory inside my heroku application and I can detail the root project named /app
in heroku
(nrb_dev) ➜ neurorehabilitation_projects git:(master) ✗ heroku run bash
Running bash on neurorehabilitation.... up, run.5840
~ $ pwd
/app
~ $
I listed the /app
content and I see all my directories and files of a similar way like I have in my development local environment django project
~ $ ls
avatars custom_storages.py django-multiselectfield-0.1.3.tar.gz functional_tests manage.py medical_encounter_information neurorehabilitation Procfile requirements requirements.txt runtime.txt userprofiles
With my error is related with this subject:
FileNotFoundError: [Errno 2] No such file or directory: '/app/neurorehabilitation/settings/static'
Then I enter to these directory /app/neurorehabilitation/settings/
but I can see that does not exist a directory named static
inside, that is the way as heroku try search:
~ $ cd /app/neurorehabilitation/settings/
~/neurorehabilitation/settings $ ls
base.py development.py __init__.py production.py staging.py testing.py
~/neurorehabilitation/settings $
And this is because according to the structure directory that I setup when I create my django project in my local development environment. I define the following:
Then, according to the previous situation ...
Why git when I perform deployment to heroku, the process is searching a path to neurorehabilitation/settings/static
when this is not setup from the originar sproject source, this mean, my project in my machine before to deploy to heroku?
What action could I take about it?
Heroku platform, when I execute the heroku run python manage.py collectstatic
command this try search a directory taht does not exist or not is setup in the structure directory of my project?
Even I try create the /app/neurorehabilitation/settings/static
folder via heroku run bash
, but this not works
(nrb_dev) ➜ neurorehabilitation_projects git:(master) ✗ heroku run bash
Running bash on test-nrb.... up, run.1604
~ $ cd neurorehabilitation/settings/
~/neurorehabilitation/settings $ mkdir static
~/neurorehabilitation/settings $ ls -all
total 36
drwx------ 3 u51683 dyno 4096 Apr 1 15:07 .
drwx------ 5 u51683 dyno 4096 Apr 1 15:02 ..
-rw------- 1 u51683 dyno 8106 Apr 1 15:02 base.py
-rw------- 1 u51683 dyno 684 Apr 1 15:02 development.py
-rw------- 1 u51683 dyno 0 Apr 1 15:02 __init__.py
-rw------- 1 u51683 dyno 930 Apr 1 15:02 production.py
-rw------- 1 u51683 dyno 530 Apr 1 15:02 staging.py
drwx------ 2 u51683 dyno 4096 Apr 1 15:07 static
-rw------- 1 u51683 dyno 488 Apr 1 15:02 testing.py
~/neurorehabilitation/settings $ exit
exit
(nrb_dev) ➜ neurorehabilitation_projects git:(master) ✗ heroku run python manage.py collectstatic
Running python manage.py collectstatic on test-nrb.... up, run.5358
You have requested to collect static files at the destination
location as specified in your settings.
This will overwrite existing files!
Are you sure you want to do this?
Type 'yes' to continue, or 'no' to cancel: yes
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python3.4/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python3.4/site-packages/django/core/management/__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/python/lib/python3.4/site-packages/django/core/management/base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "/app/.heroku/python/lib/python3.4/site-packages/django/core/management/base.py", line 399, in execute
output = self.handle(*args, **options)
File "/app/.heroku/python/lib/python3.4/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 176, in handle
collected = self.collect()
File "/app/.heroku/python/lib/python3.4/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 98, in collect
for path, storage in finder.list(self.ignore_patterns):
File "/app/.heroku/python/lib/python3.4/site-packages/django/contrib/staticfiles/finders.py", line 112, in list
for path in utils.get_files(storage, ignore_patterns):
File "/app/.heroku/python/lib/python3.4/site-packages/django/contrib/staticfiles/utils.py", line 28, in get_files
directories, files = storage.listdir(location)
File "/app/.heroku/python/lib/python3.4/site-packages/django/core/files/storage.py", line 299, in listdir
for entry in os.listdir(path):
FileNotFoundError: [Errno 2] No such file or directory: '/app/neurorehabilitation/settings/static'
(nrb_dev) ➜ neurorehabilitation_projects git:(master)
I unknown how to address this problem, Why in my heroku deployment does not create the structures directory similar to my local project?
Somebody what is the reason about it?
Is possible that in the moment I still not understad well how to works heroku at deployment instant in relation to structure directory and files when these are upload to the platform via git push heroku master
?
Any support will be highly appreciated.
Thanks for the orientation :)
I will show in this answer step by step what I made for deploying my Django application in Heroku. I hope this question be useful for the others also would like to say thanks to the people that spend time helping me with this
1. Setup my settings for my static files in heroku
The key of that is to be able to deploy my static files to Heroku was in my
settings/base.py
, acccord also to the said by ahmed and Oz123 in their responses.Particulary, I had an issue was in the value of
PROJECT_ROOT
directive. Heroku suggest thatPROJECT_ROOT
directive of this way:I did the setup
PROJECT_ROOT
(I denominedBASE_DIR
in mysettings/base.py
) as says Heroku suggested, but an error always appeared, then I took the option of leavingBASE_DIR
directive as Django has by default like myPROJECT_ROOT
directive in relation to the heroku configuration referenced above.Error I was having:
when I had the
BASE_DIR
as:Finally, my
settings/base.py
file, the content was:As my
BASE_DIR
(PROJECT_ROOT
in heroku ) I defined the file system path, finally mySTATICFILES_DIRS
directive also was compromised like Oz123 did reference me in their response. :DThen according to the deployment settings in my project (pink square in this image) my settings/production.py contains:
Is necessary also to install the dj-database-url package in my virtual environment:
Add the
dj-database-url
package/dependence in therequirements/production.txt
file of this way:This was my inconvenient for which the
collectstatic
command did not work when heroku deployed the application and trying to copy and processing my assets to amazon S3 where I have my static files according with my settings configurationIn addition, I wanted to share my heroku deployment process I think this will be useful or even anecdotic
For deploy a Django application to heroku, is necessary have in the project root the following files:
I had the myproject/requirements/ folder in the root of my Django project, but the heroku deployment process does not works of this way
Then I create in the same level or hyerarchy of requirements/ folder a requirements.txt file with the following content:
And my
requirements/production.txt
file has been stayed so:The requirements/base.txt file have all dependences or packages necessary in my project.
I needed Heroku install the
3.4 python version
in the deployment process, then was necessary to indicate it in the runtime.txt file (created in my project root) of this wayMy Procfile has been stayed so:
2. Testing the access from my machine through heroku toolbet
Is necessary install the Heroku toolbet
I test the access to heroku from my machine of this way:
3. Creating my heroku application
Accord to this response, as the application to deploy is
python/Django
the heroku application should be create of this way:Then, of this way my heroku application is created in my web dashboard
4. Setup the environment variables in my project for Heroku
I have some environment variables in my local project used for hidden my secret keys, database user, name and password, some access to my amazon web services and s3 account and the setings used for production server (
DJANGO_SETTINGS_MODULE
)Is necessary indicate to Heroku the way in that he will know these environments variables.
Accord to this link we will configure the vars for a deployed application. Then I've setup in heroku my environment variables of this way:
DJANGO_SETTINGS_MODULE
My deployment will be guided for the settings/production.py file which inherit from settings/base.py which have all the application domain packages/dependences. Then my
DJANGO_SETTINGS_MODULE
variable in heroku stay so:SECRET_KEY
I execute:
DATABASE_NAME
I execute:
DATABASE_USER
I execute:
DATABASE_PASSWORD
: Value in single quotesI execute:
I execute:
I execute:
I execute:
Then according to above options in my web dashboard the environment variables conatins:
5. Execute
commit
operation to the heroku repositoryFirst we check the files to be committed
Make the
commit
operation6. Deploy our code application to heroku repository
Before, I check my remotes repos. I have reference the
heroku
aliasDeploy to heroku repository
7. Execute the migrations process
8. I create my super user in my application deployed in the platform
And That's all. With the previous process we can deploy on heroky a Django application
Have you properly defined:
Inside your
settings.py
?Have you created it locally and added it to git (as empty directory...). The trace you have indicates that this folder is missing. I have created a simple project with the following settings:
As you can see the
STATICFILES_DIRS
contains only one directory, which does not exist:The command
collectstatic
fails:I hope this will lead you to solving your problem.