I'm trying to bundle an Angular app and deploy it as static content in a Django Rest Framework DRF application.
I don't know Django or DRF at all however, I want to take control of the routing to express something like this:
For /admin/* - delegate to built-in Django admin.
For /api/* - delegate to Django Rest Framework
For / only, and /* - treat as static content loaded from "some specified project folder", so / maps to file ./static/index.html /assets/pic.jpg maps to ./static/assets/pic.jpg
I've not been able to achieve the above. All I have is this:
A template view for index.html living at ./templates/index.html - This is the from the Angular project and is not a Django template.
Other webpack bundled content copied manually to ./static such as vendor.|hash|.bundle.js
Another problem is what to do with Assets. In the angular project, HTML views refer to assets via /assets which is at the same level as index.html
I've gotten some control over paths using this command line:
ng build --deploy-url=/static --output-path=../backend/tutorial/static
The deploy-url arg results in bundled assets references in index.html being prefixed by /static which means that Django can serve them (but not favicon.ico for some reason).
The output-path arg dumps all the assets somewhere other than the default "dist" folder.
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^api/', include(router.urls)),
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')),
url(r'^', TemplateView.as_view(template_name="index.html")),
]
Url patterns looks like the above.
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static")
]
STATIC_URL = '/static/'
These are the static settings. What I need is to be able to say "/static" and "/assets" are both static asset folders.
I'm not sure what TemplateView is (urlPatterns). Maybe there's a StaticFilesView or something that maps a URL to a path on disk?