I have a project where I am using Angular js to consume the API that I built with Django-Framework. Currently I have to start up the django api using django development server e.g., python manage.py runserver 192.168.0.185:8080' and then I have to start up the angular (this is my webclient) js server using 'python manage.py runserver 192.168.0.185:8000 ' Is there any way I can setup my django project to to run and web client so that i will no longer be seperating the development server of api and web client . That when i run api server it will also include the web client. Any idea? . Thank you.
Asked
Active
Viewed 737 times
2
-
You can serve your angularjs application to the client by returning `index.html` on `/` at `192.168.0.185:8080` – varun agarwal Apr 10 '19 at 03:30
-
@varunagarwal , can you pleaser further explain this sir ? – Apr 10 '19 at 03:34
-
is that on my settings? – Apr 10 '19 at 03:35
1 Answers
0
it should be straight forward,
In url.py , create a mapping
url(r'^$', views.index, name='index'),
In
views.py
create a function (example):
@csrf_protect
@requires_csrf_token
def index(request):
return render(request, 'index.html', content_type="text/html")
- In
index.html
, putng-app
and call theangular.js
CDN andjs
files.
That should do the work.
Make sure to use
{% verbatim %}
and{% endverbatim %}
if you want to use{{ }}
for angularJS variable interpolation. Because, Django also has the same symbol ( i.e :{{ }}
) to render the variable on it's template files.

Shashank Vivek
- 16,888
- 8
- 62
- 104
-
-
-
-
-
-
Ok, can u share more details on https://chat.stackoverflow.com/rooms/info/191573/how-to-run-django-and-angularjs-into-a-single-development-server?tab=general ? I am in ofc. Will check once i get some time :) – Shashank Vivek Apr 10 '19 at 06:14
-
-