Django, Create-react-app, Heroku

I have 3 folders in a Django web application. The folders are as follows: a folder containing settings.py (project), a folder containing models.py (application), and a folder containing an external interface application created by create-response-app.

I would like to build a reactive front, copy the assembly artifacts to a static folder, and then run the django application on heroku, but they made this process almost impossible with my current folder structure. An alternative is to smooth out the application response and have build, src, node_modules, packagejson, etc. Etc. Etc. Everything is at the root of the project, but it seems very bad.

Some configuration in settings.py:

STATICFILES_DIRS = ( os.path.join(PROJECT_ROOT, 'static'), os.path.join(BASE_DIR, 'front-end/build/static') 

)

What I run locally inside the front-end:

 npm run build 

What I return from views:

 def index(request): return HttpResponse(loader.get_template('build/index.html').render()) #above line returns index.html that is generated by npm run build 

How to deploy the project described above in Heroku so that it can find all the static resources?

+5
source share
1 answer

You can use the symlink which puts your build response in the django directory

For example, if your directory structure looks like this:

 ~/project_root/ ~/project_root/django/static/ ~/project_root/my_react_app/build 

cd to ~/project_root/django/static/ and run

 ln -s ../../my_react_app/build . 

This will create ~/project_root/django/static/build , which points to ~/project_root/my_react_app/build

0
source

Source: https://habr.com/ru/post/1267337/


All Articles