<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Nehama Mandelbaum</title>
    <description>The latest articles on DEV Community by Nehama Mandelbaum (@nehamamandelbaum).</description>
    <link>https://dev.to/nehamamandelbaum</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F693983%2F4bb3d296-f6a7-470c-8385-733dfcf09d8f.png</url>
      <title>DEV Community: Nehama Mandelbaum</title>
      <link>https://dev.to/nehamamandelbaum</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nehamamandelbaum"/>
    <language>en</language>
    <item>
      <title>How to start a Django project</title>
      <dc:creator>Nehama Mandelbaum</dc:creator>
      <pubDate>Wed, 22 Jun 2022 13:31:36 +0000</pubDate>
      <link>https://dev.to/nehamamandelbaum/how-to-start-a-django-project-26ha</link>
      <guid>https://dev.to/nehamamandelbaum/how-to-start-a-django-project-26ha</guid>
      <description>&lt;p&gt;Hello! &lt;br&gt;
In this post I'll show you how to start a project using python and Django. &lt;/p&gt;

&lt;p&gt;For this tutorial, you have to have python already installed in your computer. &lt;/p&gt;

&lt;p&gt;Step 1: Create a directory for your project and enter it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir project_name
cd project_name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 2: Create a virtual environment in your project folder: &lt;br&gt;
Unlike node.js, where the node_modules folder is created automatically when you run the command to start a project (yarn init or npm init), when using python and django, to have your project dependencies installed locally in your project directory instead of globally in your computer, you have to create your own virtual environment from scratch.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python -m venv venv

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 3: Activate your virtual environment:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;source venv/bin/activate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 4: Install the basic dependencies:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install djangorestframework black ipython
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I like using djangorestframework because it makes rest API development so much easier, and already installs django automatically. &lt;/p&gt;

&lt;p&gt;Step 5: Create a file named requirements.txt, so that pip knows which dependencies to install if you run your project in another machine:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip freeze &amp;gt; requirements.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 6: Start your project;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;django-admin startproject name_of_your_project .
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Since we already  prepared the environment in our directory, I like to use the dot in the end of the start project command, to tell django to start the app in my current folder. If I don't use it, django makes another directory inside my current directory, which in our case is unnecessary. &lt;/p&gt;

&lt;p&gt;Extra tip: Don't forget to create a gitignore, and put the venv directory in it, as well as the pycache, and your db.sqlite3 (once your run your migrations, django automatically generates a file named db.sqlite3, which is NOT recommended to upload to git)&lt;/p&gt;

&lt;p&gt;That's it for today, I hope I helped you in some small way! &lt;/p&gt;

</description>
      <category>beginners</category>
      <category>python</category>
      <category>django</category>
    </item>
  </channel>
</rss>
