Atma Atma - 3 months ago 16
Node.js Question

how to reference angular component template from django app

I have the following angular component:

angular.
module('phoneList').
component('phoneList', {
templateUrl: 'phone-list.template.html',
controller: function PhoneListController() {
this.phones = [
{
name: 'Nexus S',
snippet: 'Fast just got faster with Nexus S.',
age: 1
}, {
name: 'Motorola XOOM™ with Wi-Fi',
snippet: 'The Next, Next Generation tablet.',
age: 2
}, {
name: 'MOTOROLA XOOM™',
snippet: 'The Next, Next Generation tablet.',
age: 3
}
];

this.orderProp = 'age';
}
});


This template:
templateUrl: 'phone-list.template.html',
and the component are inside of my django app.

I have placed the template in:


myapp > templates > myapp > phone-list.template.html


The reference gives me a 404 as well as angular error:


http://127.0.0.1:8000/myapp/phone-list.template.html


Do I need to create a django url entry?
Do I need use a django url tag in the component?

Answer

Templates in the templates folder in Django are available to the template loader only. They are not served and can not be accessed via HTTP directly. But that is what Angular does.

If you need to render the template in Django, make sure you have created a view and an endpoint for it in your urls.py.

If no rendering is needed and Django can use the template directly serve them like static files.

Comments