<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>djangorestframework Archives | Clever Cloud</title>
	<atom:link href="https://www.clever.cloud/blog/tag/djangorestframework/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.clever.cloud/blog/tag/djangorestframework/</link>
	<description>From Code to Product</description>
	<lastBuildDate>Tue, 12 Feb 2019 15:02:00 +0000</lastBuildDate>
	<language>en-GB</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://cdn.clever-cloud.com/uploads/2023/03/cropped-cropped-favicon-32x32.png</url>
	<title>djangorestframework Archives | Clever Cloud</title>
	<link>https://www.clever.cloud/blog/tag/djangorestframework/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Bring your API to the World Within 3 Minutes</title>
		<link>https://www.clever.cloud/blog/engineering/2019/02/12/create-an-api-with-python/</link>
		
		<dc:creator><![CDATA[Valeriane Venance]]></dc:creator>
		<pubDate>Tue, 12 Feb 2019 15:02:00 +0000</pubDate>
				<category><![CDATA[Engineering]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[djangorestframework]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[runtime]]></category>
		<guid isPermaLink="false">https://www2.cleverapps.io/wp/blog/technology/2019/02/12/create-an-api-with-python/</guid>

					<description><![CDATA[<p><img width="1400" height="540" src="https://cdn.clever-cloud.com/uploads/2021/08/api-to-the-world-1.jpg" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="api to the world 1" decoding="async" fetchpriority="high" srcset="https://cdn.clever-cloud.com/uploads/2021/08/api-to-the-world-1.jpg 1400w, https://cdn.clever-cloud.com/uploads/2021/08/api-to-the-world-1-300x116.jpg 300w, https://cdn.clever-cloud.com/uploads/2021/08/api-to-the-world-1-1024x395.jpg 1024w, https://cdn.clever-cloud.com/uploads/2021/08/api-to-the-world-1-768x296.jpg 768w, https://cdn.clever-cloud.com/uploads/2021/08/api-to-the-world-1-1368x528.jpg 1368w" sizes="(max-width: 1400px) 100vw, 1400px" /></p><p>A couple years ago, I was a developer for a startup which has almost no test coverage. Super enthusiastic me from the past spent a few weeks coding tests, and factories… all that based on the gem FactoryGirl. Two days before I’m satisfied of what I’ve done, they announce that FactoryGirl needs to be upgraded to <a href="https://github.com/thoughtbot/factory_bot_rails" rel="noopener noreferrer" target="_blank">FactoryBot</a>.</p>
<span id="more-2816"></span>

<p>A few days ago, I’m like hey I want to talk about <a href="https://www.django-rest-framework.org/" rel="noopener noreferrer" target="_blank">DRF</a> on Clever Cloud, I’ll make a little API, who cares which python I’m using, let’s use <a href="https://pythonclock.org/" rel="noopener noreferrer" target="_blank">2.7</a>! So I’m coding the project, making <a href="https://github.com/vvenance/personal-website-drf-backend/blob/master/README.md" rel="noopener noreferrer" target="_blank">a nice readme</a> and the python team finally decides to explicitly invite users to migrate to <a href="https://www.python.org/download/releases/3.0/" rel="noopener noreferrer" target="_blank">python 3</a>….</p>
<p>Anyway ! the project is <a href="https://github.com/vvenance/personal-website-drf-backend" rel="noopener noreferrer" target="_blank">here</a> all you have to do is to <code>git clone</code> the repo or have your own DRF repo locally.</p>
<p>If you use your own repo, make sure to have the following lines in your settings.py</p>
<pre><code class="language-python">PRODUCTION = True
if PRODUCTION:
    DATABASES = {
        &#39;default&#39;: {
            &#39;ENGINE&#39;: &#39;django.db.backends.postgresql_psycopg2&#39;,
            &#39;NAME&#39;: os.environ.get(&#39;POSTGRESQL_ADDON_DB&#39;),
            &#39;USER&#39;: os.environ.get(&#39;POSTGRESQL_ADDON_USER&#39;),
            &#39;PASSWORD&#39;: os.environ.get(&#39;POSTGRESQL_ADDON_PASSWORD&#39;),
            &#39;HOST&#39;: os.environ.get(&#39;POSTGRESQL_ADDON_HOST&#39;),
            &#39;PORT&#39;: os.environ.get(&#39;POSTGRESQL_ADDON_PORT&#39;),
        }
    }
</code></pre>
<p>go to <a href="https://console.clever-cloud.com/" rel="noopener noreferrer" target="_blank">Clever Cloud console</a> and select create a new application. Select brand new app.</p>
<figure style="position:relative;width:50%;height:auto;margin:0 auto">
    <img data-action="zoom"  alt="select create a new clever cloud application" src="https://cdn.clever-cloud.com/uploads/2021/08/click-create-app.png"/>
</figure>
<figure style="position:relative;width:50%;height:auto;margin:0 auto">
    <img data-action="zoom"  alt="create a new application" src="https://cdn.clever-cloud.com/uploads/2021/08/create-new-app.png"/>
</figure>

<p>Click next and select python, then name you application.</p>
<figure style="position:relative;width:50%;height:auto;margin:0 auto">
    <img data-action="zoom" alt="select python on the clever cloud console" src="https://cdn.clever-cloud.com/uploads/2021/08/select-python.png"/>
</figure>
<figure style="position:relative;width:50%;height:auto;margin:0 auto">
    <img data-action="zoom"  alt="name the application" src="https://cdn.clever-cloud.com/uploads/2021/08/name-clever-app.png"/>
</figure>

<p>The Clever Cloud console will ask you if you want to link an add on. Select postgreSQL and name your add-on</p>
<figure style="position:relative;width:50%;height:auto;margin:0 auto">
    <img data-action="zoom"  alt="select postgreSQL application" src="https://cdn.clever-cloud.com/uploads/2021/08/select-postgres.png"/>
</figure>
<figure style="position:relative;width:50%;height:auto;margin:0 auto">
    <img data-action="zoom"  alt="name the add on" src="https://cdn.clever-cloud.com/uploads/2021/08/name-add-on.png"/>
</figure>

<p>Just wait for the Clever console to set up your add on and application.</p>
<p>When your application is ready, you&#39;re invited to add environment variables.</p>
<p>If you use my project click on the expert mode button</p>
<figure>
  <img data-action="zoom" alt="select expert mode for adding env variables" src="https://cdn.clever-cloud.com/uploads/2021/08/expert-mode.png"/>
</figure>

<p>and paste the following :</p>
<pre><code class="language-bash">CC_PYTHON_MODULE=personal_website_backend.wsgi:application
CUSTOM_SECRET_KEY=your_custom_secret_key
PORT=8080
PRODUCTION=True
</code></pre>
<p>You can generate a secret key 50 chars long (DRF requirement) <a href="http://www.unit-conversion.info/texttools/random-string-generator/" rel="noopener noreferrer" target="_blank">here</a>.</p>
<p>If you use your own repo, add the env vars you need, but make sure to have at least <code>CC_PYTHON_MODULE=&lt;your_module_name&gt;.wsgi:application</code></p>
<p>Then click next, a new screen will display with a git command to add a new remote to your repo and do your first deploy</p>
<figure>
  <img data-action="zoom" alt="clever cloud instructions for git remote" src="https://cdn.clever-cloud.com/uploads/2021/08/clever-git-instructions.png"/>
</figure>

<p>Copy these lines and paste them directly in your console while being in your repo</p>
<pre><code class="language-bash">git remote add clever git+ssh:\/\/git@push-par-clevercloud-customers.services.clever-cloud.com/&lt;your_app_id&gt;.git
git push -u clever master
</code></pre>
<p>Go back to Clever Cloud console and just look at the deployment logs of your app. It will tell you when your app is up, so just go to the overview page and click on the link symbol to visit your app.</p>
<p>If you want to see the full procedure live, have a look <a href="https://www.useloom.com/share/cc5352092d994d6fa95629c29194f1b5" rel="noopener noreferrer" target="_blank">here</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><img width="1400" height="540" src="https://cdn.clever-cloud.com/uploads/2021/08/api-to-the-world-1.jpg" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="api to the world 1" decoding="async" srcset="https://cdn.clever-cloud.com/uploads/2021/08/api-to-the-world-1.jpg 1400w, https://cdn.clever-cloud.com/uploads/2021/08/api-to-the-world-1-300x116.jpg 300w, https://cdn.clever-cloud.com/uploads/2021/08/api-to-the-world-1-1024x395.jpg 1024w, https://cdn.clever-cloud.com/uploads/2021/08/api-to-the-world-1-768x296.jpg 768w, https://cdn.clever-cloud.com/uploads/2021/08/api-to-the-world-1-1368x528.jpg 1368w" sizes="(max-width: 1400px) 100vw, 1400px" /></p><p>A couple years ago, I was a developer for a startup which has almost no test coverage. Super enthusiastic me from the past spent a few weeks coding tests, and factories… all that based on the gem FactoryGirl. Two days before I’m satisfied of what I’ve done, they announce that FactoryGirl needs to be upgraded to <a href="https://github.com/thoughtbot/factory_bot_rails" rel="noopener noreferrer" target="_blank">FactoryBot</a>.</p>
<span id="more-2816"></span>

<p>A few days ago, I’m like hey I want to talk about <a href="https://www.django-rest-framework.org/" rel="noopener noreferrer" target="_blank">DRF</a> on Clever Cloud, I’ll make a little API, who cares which python I’m using, let’s use <a href="https://pythonclock.org/" rel="noopener noreferrer" target="_blank">2.7</a>! So I’m coding the project, making <a href="https://github.com/vvenance/personal-website-drf-backend/blob/master/README.md" rel="noopener noreferrer" target="_blank">a nice readme</a> and the python team finally decides to explicitly invite users to migrate to <a href="https://www.python.org/download/releases/3.0/" rel="noopener noreferrer" target="_blank">python 3</a>….</p>
<p>Anyway ! the project is <a href="https://github.com/vvenance/personal-website-drf-backend" rel="noopener noreferrer" target="_blank">here</a> all you have to do is to <code>git clone</code> the repo or have your own DRF repo locally.</p>
<p>If you use your own repo, make sure to have the following lines in your settings.py</p>
<pre><code class="language-python">PRODUCTION = True
if PRODUCTION:
    DATABASES = {
        &#39;default&#39;: {
            &#39;ENGINE&#39;: &#39;django.db.backends.postgresql_psycopg2&#39;,
            &#39;NAME&#39;: os.environ.get(&#39;POSTGRESQL_ADDON_DB&#39;),
            &#39;USER&#39;: os.environ.get(&#39;POSTGRESQL_ADDON_USER&#39;),
            &#39;PASSWORD&#39;: os.environ.get(&#39;POSTGRESQL_ADDON_PASSWORD&#39;),
            &#39;HOST&#39;: os.environ.get(&#39;POSTGRESQL_ADDON_HOST&#39;),
            &#39;PORT&#39;: os.environ.get(&#39;POSTGRESQL_ADDON_PORT&#39;),
        }
    }
</code></pre>
<p>go to <a href="https://console.clever-cloud.com/" rel="noopener noreferrer" target="_blank">Clever Cloud console</a> and select create a new application. Select brand new app.</p>
<figure style="position:relative;width:50%;height:auto;margin:0 auto">
    <img data-action="zoom"  alt="select create a new clever cloud application" src="https://cdn.clever-cloud.com/uploads/2021/08/click-create-app.png"/>
</figure>
<figure style="position:relative;width:50%;height:auto;margin:0 auto">
    <img data-action="zoom"  alt="create a new application" src="https://cdn.clever-cloud.com/uploads/2021/08/create-new-app.png"/>
</figure>

<p>Click next and select python, then name you application.</p>
<figure style="position:relative;width:50%;height:auto;margin:0 auto">
    <img data-action="zoom" alt="select python on the clever cloud console" src="https://cdn.clever-cloud.com/uploads/2021/08/select-python.png"/>
</figure>
<figure style="position:relative;width:50%;height:auto;margin:0 auto">
    <img data-action="zoom"  alt="name the application" src="https://cdn.clever-cloud.com/uploads/2021/08/name-clever-app.png"/>
</figure>

<p>The Clever Cloud console will ask you if you want to link an add on. Select postgreSQL and name your add-on</p>
<figure style="position:relative;width:50%;height:auto;margin:0 auto">
    <img data-action="zoom"  alt="select postgreSQL application" src="https://cdn.clever-cloud.com/uploads/2021/08/select-postgres.png"/>
</figure>
<figure style="position:relative;width:50%;height:auto;margin:0 auto">
    <img data-action="zoom"  alt="name the add on" src="https://cdn.clever-cloud.com/uploads/2021/08/name-add-on.png"/>
</figure>

<p>Just wait for the Clever console to set up your add on and application.</p>
<p>When your application is ready, you&#39;re invited to add environment variables.</p>
<p>If you use my project click on the expert mode button</p>
<figure>
  <img data-action="zoom" alt="select expert mode for adding env variables" src="https://cdn.clever-cloud.com/uploads/2021/08/expert-mode.png"/>
</figure>

<p>and paste the following :</p>
<pre><code class="language-bash">CC_PYTHON_MODULE=personal_website_backend.wsgi:application
CUSTOM_SECRET_KEY=your_custom_secret_key
PORT=8080
PRODUCTION=True
</code></pre>
<p>You can generate a secret key 50 chars long (DRF requirement) <a href="http://www.unit-conversion.info/texttools/random-string-generator/" rel="noopener noreferrer" target="_blank">here</a>.</p>
<p>If you use your own repo, add the env vars you need, but make sure to have at least <code>CC_PYTHON_MODULE=&lt;your_module_name&gt;.wsgi:application</code></p>
<p>Then click next, a new screen will display with a git command to add a new remote to your repo and do your first deploy</p>
<figure>
  <img data-action="zoom" alt="clever cloud instructions for git remote" src="https://cdn.clever-cloud.com/uploads/2021/08/clever-git-instructions.png"/>
</figure>

<p>Copy these lines and paste them directly in your console while being in your repo</p>
<pre><code class="language-bash">git remote add clever git+ssh:\/\/git@push-par-clevercloud-customers.services.clever-cloud.com/&lt;your_app_id&gt;.git
git push -u clever master
</code></pre>
<p>Go back to Clever Cloud console and just look at the deployment logs of your app. It will tell you when your app is up, so just go to the overview page and click on the link symbol to visit your app.</p>
<p>If you want to see the full procedure live, have a look <a href="https://www.useloom.com/share/cc5352092d994d6fa95629c29194f1b5" rel="noopener noreferrer" target="_blank">here</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
