I'm trying to keep my front and back ends completely separate. Front end is a template developed in node-land with (I hope) minimal or no context involvement, back-end is a set of TemplateViews
and an API.
I'm building my frontend to my frontend
directory, so that's easy enough, I just set in settings.py
:
TEMPLATES = [
{
"DIRS": ["frontend/"]
...
I'm running into difficulties when these templates reference assets like:
<link rel="assets/css/foobar.css" />
foobar.css
is present at the relevant location, but the dev server doesn't know to look there. Obviously in production the proxy server will be serving these files directly, but can I get the django dev server to do that while I'm developing? I really want to avoid prefixing with {{ STATIC_URL }}
and other template tags that couple the back end to the templates.
Figured it out: Have a separate dev settings file that overrides:
STATIC_ROOT = os.path.join(BASE_DIR, 'frontend/build/assets/')
STATIC_URL = 'assets/'
Now the dev server will be able to look in the correct location without relying on {% static %}
tags.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.