<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Jyoti Prakash Das on Medium]]></title>
        <description><![CDATA[Stories by Jyoti Prakash Das on Medium]]></description>
        <link>https://medium.com/@jdas388?source=rss-b612021f067e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*uiVnFRumjhSpT-tx5vRPng.jpeg</url>
            <title>Stories by Jyoti Prakash Das on Medium</title>
            <link>https://medium.com/@jdas388?source=rss-b612021f067e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 15:08:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jdas388/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Getting Started with Django and Angular 7]]></title>
            <link>https://medium.com/@jdas388/getting-started-with-django-and-angular-7-655d9a2ed18c?source=rss-b612021f067e------2</link>
            <guid isPermaLink="false">https://medium.com/p/655d9a2ed18c</guid>
            <category><![CDATA[django]]></category>
            <category><![CDATA[angular-7]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[python3]]></category>
            <dc:creator><![CDATA[Jyoti Prakash Das]]></dc:creator>
            <pubDate>Wed, 03 Apr 2019 20:32:25 GMT</pubDate>
            <atom:updated>2019-04-03T20:32:25.296Z</atom:updated>
            <content:encoded><![CDATA[<p>When starting a new website from scratch, All developers have some questions in mind, on what technology should they use, so that the website can perform better, be scalable , powerful, secure and be smooth in all aspects and yet the UI be beautiful and sleek.</p><p>So why choose Django ?</p><p>Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design. Django was created with a focus on faster development. So that developers won’t have to spend much time on hassels of web development, and can directly jump into writing real code.</p><p>Secure ? Django provides many inbuilt security modules that helps in securing the needful and helps developers avoid many common security mistakes.</p><p>Scalable? Many of world’s biggest websites are made on Django, due to the simple fact as how fast and scalable django is.</p><p>Why choose Angular?</p><p>A google-backed project that is used to create production-ready large applications with very few lines of code and effort. Angular has proved its dominance over speed and beautiful UI development since its inception. Angular puts you in control over scalability. Meet huge data requirements by building data models on RxJS, Immutable.js or another similar module.</p><p>So let’s get started now..</p><p>1- Lets create an angular app that will be integrated in Django.</p><pre>ng new AngularApp</pre><p>now lets create a global service that will help us to keep track of the global variables and function.</p><pre>ng g service global</pre><p>now let’s personalize the app with our content and multiple API call to get some random data from Django.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/1*Q5-GuyeNH_ZhlOsvSrOg6g.png" /><figcaption>Define these to functions in app.component.ts that would interact with Django through the API calls.</figcaption></figure><p>As you can see in the above functions, I’ve kept the URLs as some global variables, so that whenever we have a need to change the URLs or base URL, we can directly go to global.service.ts and change those, without having to change it everywhere inside the code.</p><p>These global variables should be declaraed in global.service.ts as below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/567/1*wDE-ywBEPxLZ8YqUL1A_Mg.png" /><figcaption>global.service.ts should look something like this</figcaption></figure><p>now design your page according to you, add some buttons and bind them with the functions we created in app.component.ts and serve it to see if everything is working..</p><pre>ng serve</pre><p>2- Now lets create the Django app, that will be base for all interaction to back-end for the angular app that we just created.</p><pre>django-admin startproject djangoApp<br>cd djangoApp<br>python manage.py startapp my_app</pre><p>These commands will create the django app and make it ready to start working.</p><p>Before we jump into anything, lets make some small adjustments, so that our Angular app can be integrated and work smoothly in django.</p><ul><li>First create two folders inside my_app, “static” and “templates”. static will be the folder, where all assets, external js files, external css file will be there. templates will be the folder, where the .html files will reside.</li><li>now, go to settings.py and add “my-app” as an INSTALLED_APPS.</li><li>for allowing cross-origin-requests, we will add corsheaders in INSTALLED_APPS and will provide the whitelist ips.</li><li>finally, we will instruct django to load all the files from staic folder, for that we will add 3 lines of code into settings.py</li><li>install “pip install django-cors-headers”</li></ul><pre>STATIC_URL = &#39;/static/&#39;</pre><pre>STATICFILES_DIRS = [</pre><pre>os.path.join(BASE_DIR, &quot;static&quot;),</pre><pre>]</pre><p>The final settings.py will look like</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/635/1*YcTC1IEU1lQHydl9i-zr7g.png" /><figcaption>settings.py</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/545/1*PsqbTYCat9qYOfhuGQNXvw.png" /><figcaption>settings.py</figcaption></figure><p>Now lets add the methods in views.py, that will respond to the call from angular.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/583/1*cYsHFU9YnQFvOGuRHdENFw.png" /></figure><p>And we will add the paths in urls.py, so that when django can route the functions to its appropriate method declaration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/537/1*78-LPrQwX8GErSZul3aBTg.png" /></figure><p>now serve it…it should start in development server at localhost:8000 (default).</p><p>As you can see, we will be able to call Django functions from angular though the API calls.</p><p>Now let’s start the real integration</p><p>By Far , we are able to run Angular App on port 4200 and Django on port 8000, but we need to run both on the same port( That’t the whole point of this post right!). So, here is what we will do</p><p>Firstly, Let’s build the Angular App using command as</p><pre>ng build --prod</pre><p>This will create a folder inside your app, named as “dist”. Navigate to “dist” and there will be a file with the name same as your angular app. Copy the below mentioned files from that folder.</p><pre>inline.**********.bundle.js<br>main.************.bundle.js<br>polyfills.***********.bundle.js<br>styles.*************.bundle.css</pre><p>Copy these files to the static folder, in our Django app.</p><p>Now, copy the</p><pre>index.html</pre><p>from dist, to the templates folder that we had created.</p><p>Now to tell Django to load our UI, we will ave to make some changes in the index.html file as</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/741/1*5yq-39EHVyjzdwYniEOQJA.png" /><figcaption>index.html</figcaption></figure><p>Here in index.html, we add the static path to all the external js and css files that we imported from angular, so that Django can load those from the static folder.</p><p>Now finally, run</p><pre>python manage.py runserver</pre><p>navigate to localhost:4000 and see your app in action!!</p><p>Cheers!!! You now know how to use the power of Django + Angular 7 to build powerful and Secure apps with Stylish UI.</p><p>Find the Github repo link <a href="https://github.com/JyotiPrkash/Django-Angular-App">here</a> .</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=655d9a2ed18c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>