<?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 Kakar Nyori on Medium]]></title>
        <description><![CDATA[Stories by Kakar Nyori on Medium]]></description>
        <link>https://medium.com/@nyorikakar?source=rss-4abad2f2de56------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Vw7NFMqqg7lQS22JiGMtNw.jpeg</url>
            <title>Stories by Kakar Nyori on Medium</title>
            <link>https://medium.com/@nyorikakar?source=rss-4abad2f2de56------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 08:04:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nyorikakar/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[Test driven development with Pytest and Django]]></title>
            <link>https://nyorikakar.medium.com/test-driven-development-with-pytest-and-django-f688ed808b28?source=rss-4abad2f2de56------2</link>
            <guid isPermaLink="false">https://medium.com/p/f688ed808b28</guid>
            <category><![CDATA[pytest]]></category>
            <category><![CDATA[django-rest-framework]]></category>
            <category><![CDATA[docker-compose]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[django]]></category>
            <dc:creator><![CDATA[Kakar Nyori]]></dc:creator>
            <pubDate>Mon, 02 Aug 2021 14:42:54 GMT</pubDate>
            <atom:updated>2021-08-02T14:44:43.712Z</atom:updated>
            <content:encoded><![CDATA[<p>In this part, we will create our Task app and continue with Test-driven development we started previously on <a href="https://nyorikakar.medium.com/test-driven-development-with-pytest-django-and-docker-set-up-8f7fb7ccbfa5">Test driven development with Pytest, Django and Docker — Set up</a>.</p><h3>The app</h3><p>Let’s create the app</p><pre>python manage.py startapp tasks</pre><p>To include the app in our project, we need to add a reference to its configuration class in the <a href="https://docs.djangoproject.com/en/3.2/ref/settings/#std:setting-INSTALLED_APPS"><strong>INSTALLED_APPS</strong></a> setting:</p><pre>INSTALLED_APPS = [<br>    ...<br>    ...<br>    &#39;tasks.apps.TasksConfig&#39;,<br>]</pre><p>Delete the <em>test.py</em> file from the task app. Instead, create a new directory called <strong>tests/</strong> inside the task app, and create an <strong>__init__.py</strong> file for it to be a python package.</p><p>We will be creating new test files (inside the task’s <strong>tests/ </strong>directory) for each file that we are going to test with Pytest. For example, for <strong>models.py</strong> we will create <strong>test_models.py</strong>.</p><p>And since we are following Test Driven Development, we will create our tests first.</p><h3>The models</h3><p>Create a <strong>tasks/tests/test_models.py</strong> and add the following</p><pre>import pytest<br>from mixer.backend.django import mixer</pre><pre><a href="http://twitter.com/pytest">@pytest</a>.mark.django_db<br>class TestTask:<br>    def test_model(self):<br>        obj = mixer.blend(&#39;tasks.Task&#39;)<br>        assert obj.pk == 1, &#39;Should create a task instance&#39;</pre><p>Run pytest and you can expect similar resuls:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*DV61hJJbzzJDunMXVgradA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/961/1*-0pkdBVo--8VDg0qfdouVg.jpeg" /></figure><p>We got our first Red!</p><p>Remember TDD is all about Red — Green — Refactor cycle:</p><ul><li>Red: Write test cases first and check the Errors</li><li>Green: Solve the error</li><li>Refactor: If need be then refactor the code</li></ul><p>Now that we got our error, it is telling us there is no Task class in our tasks app. Let’s create our Task model.</p><p>Update tasks/models.py with the following:</p><pre>from django.db import models</pre><pre>class Task(models.Model):<br>    title = models.CharField(max_length=100)<br>    is_completed = models.BooleanField(default=False)</pre><p>Now run the test again and you can expect similar results:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/995/1*u4N1sXfVjQeqEjDcRGP_cA.jpeg" /></figure><p>Our task model will also have an excerpt method for its title, and so it will return the first few characters from the title. So let’s first update our test for that.</p><p>Update <strong>tasks/tests/test_models.py</strong></p><pre>import pytest<br>from mixer.backend.django import mixer</pre><pre><a href="http://twitter.com/pytest">@pytest</a>.mark.django_db<br>class TestTask:<br>    def test_model(self):<br>        obj = mixer.blend(&#39;tasks.Task&#39;)<br>        assert obj.pk == 1, &#39;Should create a task instance&#39;</pre><pre>    def test_excerpt(self):<br>        obj = mixer.blend(&#39;tasks.Task&#39;, title=&#39;Buy milk from the market&#39;)<br>        result = obj.get_excerpt(8)<br>        assert result == &#39;Buy milk&#39;, &#39;Should return first few characters&#39;</pre><p>Run the test and you can expect similar results:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*XmmpdpkQhMlSFPZW0uOTXQ.jpeg" /></figure><p>Since we don’t have a get_excerpt method, the error is telling us about that.</p><p>Let’s update our <strong>tasks/models.py</strong> to have our green!</p><pre>from django.db import models</pre><pre>class Task(models.Model):<br>    title = models.CharField(max_length=100)<br>    is_completed = models.BooleanField(default=False)</pre><pre>    def get_excerpt(self, total_char):<br>        return self.title[:total_char]</pre><p>Run the test again to check if the test has passed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/986/1*W3-b7VgWnnhm5PwNc9guYw.jpeg" /></figure><h3>The admin</h3><p>As we did with testing our models, we will create our tests first for the admin.py as well.</p><p>Create a <strong>tasks/tests/test_admin.py</strong> file and add the following:</p><pre>from .. import models<br>from .. import admin<br>from django.contrib.admin.sites import AdminSite<br>import pytest<br>from mixer.backend.django import mixer</pre><pre><a href="http://twitter.com/pytest">@pytest</a>.mark.django_db<br>class TestTaskAdmin:<br>    def test_excerpt(self):<br>        site = AdminSite()<br>        task_admin = admin.TaskAdmin(models.Task, site)</pre><pre>        obj = mixer.blend(&#39;tasks.Task&#39;, <em>title</em>=&#39;Buy milk from the market&#39;)<br>        result = task_admin.excerpt(obj)<br>        <em>assert</em> result == &#39;Buy milk&#39;, &#39;Should return first few characters&#39;</pre><p>Run the test and you can expect similar output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/993/1*hFfhJZ4ToqYgVyy0uQN6Jw.jpeg" /></figure><p>Since there is no TaskAdmin in our admin.py, we will need to write that out. Update <strong>task/admin.py</strong> with the following:</p><pre>from django.contrib import admin<br>from . import models</pre><pre>class TaskAdmin(admin.ModelAdmin):<br>    model = models.Task<br>    list_display = (&#39;excerpt&#39;,)</pre><pre>    def excerpt(self, obj):<br>        return obj.get_excerpt(8)</pre><pre>admin.site.register(models.Task, TaskAdmin)</pre><p>Run the test again, and you can expect similar output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1005/1*WZ8IOtpaKzj33_2qVNCpOw.jpeg" /></figure><p>Yay! Now that, most of the app is tested. We will see how to follow test driven development with the <em>views.py</em> and Django rest framework in the next part.</p><p>If you want, you can check out the <a href="https://github.com/NyoriK/Test-driven-development-with-Django-Pytest-Docker-and-Django-rest-framework/tree/tdd-with-django-pytest">repo</a>.</p><p>See you soon!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f688ed808b28" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Test Driven Development with PyTest, Django and Docker — Set up]]></title>
            <link>https://nyorikakar.medium.com/test-driven-development-with-pytest-django-and-docker-set-up-8f7fb7ccbfa5?source=rss-4abad2f2de56------2</link>
            <guid isPermaLink="false">https://medium.com/p/8f7fb7ccbfa5</guid>
            <category><![CDATA[django-rest-framework]]></category>
            <category><![CDATA[pytest]]></category>
            <category><![CDATA[docker-compose]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Kakar Nyori]]></dc:creator>
            <pubDate>Tue, 27 Jul 2021 07:47:07 GMT</pubDate>
            <atom:updated>2021-07-27T07:47:07.505Z</atom:updated>
            <content:encoded><![CDATA[<h3>Test Driven Development with PyTest, Django and Docker — Set up</h3><p>Test-driven development is going through the process of writing the test first, then writing the required code to pass the test. Finally, if need be, refactor the code. So it is a cycle of Red — Green — Refactor.</p><ol><li><strong>Red</strong> : Since we are writing our test for the provided specifications, we will get errors as we still don’t have the code to test for.</li><li><strong>Green</strong> : After we get errors from running our test, we need to write the minimum code required to pass our test.</li><li><strong>Refactor</strong> : <em>This is optional</em>. If you need, you can update and optimize your code.</li></ol><p>We will create a simple Todo app. I will be working on VSCode, and along the way let you know how set up VSCode for our project.</p><h3>Define our project’s components</h3><p>Create a directory for your project and open it on your code editor.</p><pre>mkdir docker-django-todos-project # root directory of our project</pre><pre>cd docker-django-todos-project</pre><pre>code .   # open in vscode</pre><p>Now create a Dockerfile in your root (project’s) directory and add the following:</p><pre># syntax=docker/dockerfile:1<br>FROM python:3<br>ENV PYTHONUNBUFFERED=1<br>WORKDIR /code<br>COPY requirements.txt /code/<br>RUN pip install -r requirements.txt<br>COPY . /code/</pre><p>Create a <strong><em>requirements.txt</em></strong> file (root directory) for Django project’s dependencies:</p><pre>Django&gt;=3.0,&lt;4.0<br>psycopg2-binary&gt;=2.8<br>djangorestframework<br>pytest<br>pytest-django<br>git+git://github.com/mverteuil/pytest-ipdb.git<br>pytest-cov<br>mixer<br>mock</pre><p>Finally, let’s create a docker-compose.yml file in the root directory and add the following:</p><pre>version: &quot;3.9&quot;<br>   <br>services:<br>  db:<br>    image: postgres<br>    volumes:<br>      - ./data/db:/var/lib/postgresql/data<br>    environment:<br>      - POSTGRES_DB=postgres<br>      - POSTGRES_USER=postgres<br>      - POSTGRES_PASSWORD=postgres<br>    healthcheck:<br>        test: [&quot;CMD-SHELL&quot;, &quot;pg_isready -U postgres&quot;]<br>        interval: 5s<br>        timeout: 5s<br>        retries: 5<br>  web:<br>    build: .<br>    command: python manage.py runserver 0.0.0.0:8000<br>    volumes:<br>      - .:/code<br>    ports:<br>      - &quot;8000:8000&quot;<br>    depends_on:<br>      db:<br>        condition: service_healthy</pre><h4>Create a Django project</h4><p>From the root (project’s) directory, create the Django project by running the docker-compose run command as follows:</p><pre>docker-compose run web django-admin startproject todos_project .</pre><blockquote>Notice the <strong><em>.</em></strong> at the end of the command to start the project with the <em>project name</em>. It starts the project in the current directory without creating a new directory for the project.</blockquote><h4>Connect the database</h4><p>In your project directory, edit the todos_project/settings.py file, and replace the DATABASES = ... with the following:</p><pre>DATABASES = {<br>    &#39;default&#39;: {<br>        &#39;ENGINE&#39;: &#39;django.db.backends.postgresql&#39;,<br>        &#39;NAME&#39;: &#39;postgres&#39;,<br>        &#39;USER&#39;: &#39;postgres&#39;,<br>        &#39;PASSWORD&#39;: &#39;postgres&#39;,<br>        &#39;HOST&#39;: &#39;db&#39;,<br>        &#39;PORT&#39;: 5432,<br>    }<br>}</pre><p>Let’s see if everything is working by running docker-compose up from the root directory:</p><pre>docker-compose up</pre><p>If you see this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ynkqHJRMdPjaw4hG6YfqwQ.jpeg" /></figure><p>then open your browser and go to the <a href="http://localhost:8000/">localhost:8000</a> and you should see this wonderful page!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1006/1*1Xs0G-UB7lKoepANML3J4w.jpeg" /></figure><h4>VSCode settings</h4><p>We will use our project’s docker container as the python interpreter, and our VSCode terminal can access the container as well.</p><p>If you started the containers from the VsCode terminal, then press <em>ctrl + c</em> and stop the container. Again start the containers in detached mode, with -d flag:</p><pre>docker-compose up -d</pre><p>Once the container is running in the background, open the command palette by pressing <em>ctrl + shift + p</em></p><p>Search “<strong><em>remote containers</em></strong>” and select Remote-Containers: Attach to Running Container and then select your docker Django web container docker-todos-project-django_web</p><blockquote>Note: The docker container must be running for this to work.</blockquote><p>This will open a new VsCode window. You can now close the previous VSCode.</p><ol><li>On the Explorer, click on the open folder and select or enter /code and enter.</li><li>Install the Python (by Microsoft) extension in the container.</li></ol><h3>Introducing PyTest</h3><p>Create <strong>test_settings.py</strong> file inside todos_project/ and add the following:</p><pre>from .settings import *</pre><pre>DATABASES = {<br>    &#39;default&#39;: {<br>        &#39;ENGINE&#39;: &#39;django.db.backends.sqlite3&#39;,<br>        &#39;NAME&#39;: BASE_DIR / &#39;db.sqlite3&#39;,<br>    }<br>}</pre><pre>EMAIL_BACKEND = &#39;django.core.mail.backends.locmem.EmailBackend&#39;</pre><p>Create <strong>pytest.ini</strong> file in the root directory and add the following:</p><pre>[pytest]<br>DJANGO_SETTINGS_MODULE = todos_project.test_settings<br>; # -- recommended but optional:<br>; python_files = tests.py test_*.py *_tests.py<br>addopts = --nomigrations --cov=. --cov-report=html</pre><p>Create a <strong>.coveragerc</strong> file in the root directory for the project’s Pytest coverage report and add the following:</p><pre>[run]<br>omit = <br>    *apps.py,<br>    *migrations/*.py,<br>    *settings*.py,<br>    *tests/*.py,<br>    *urls.py,<br>    *wsgi.py,<br>    *asgi.py,<br>    *test.py,<br>    manage.py</pre><p>Let’s check if Pytest is working by running:</p><pre>pytest</pre><p>And you should see this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/909/1*9Ej1wEGUTSn4dpktfgn1LA.jpeg" /></figure><p>Running pytest will also create a <strong>htmlcov</strong> directory in your project’s root directory. You can check your coverage report by opening <strong>htmlcov/index.html</strong> in your browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/559/1*xXmNUmhYcuRuCE8FtIEQxQ.jpeg" /></figure><p>The final project structure should look something like this:</p><pre>- data<br>- - db<br>- - - ...<br>- - - ...<br>- db.sqlite3<br>- docker-compose.yml<br>- Dockerfile<br>- htmlcov<br>- - index.html<br>- - ...<br>- - ...<br>- manage.py<br>- pytest.ini<br>- requirements.txt<br>- todos_project<br>- - asgi.py<br>- - settings.py<br>- - test_settings.py<br>- - urls.py<br>- - wsgi.py<br>- - __init__.py</pre><p>Now that all the required work needed for PyTest is done, we will continue with Test Driven Development and a Django App in the next part.</p><p>If you want, you can check out the <a href="https://github.com/NyoriK/Test-driven-development-with-Django-Pytest-Docker-and-Django-rest-framework/tree/template-for-tdd-django-pytest-docker-django-rest-framework">repo</a>.</p><p>See you on the other side!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8f7fb7ccbfa5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Django and real-time with Centrifugo]]></title>
            <link>https://nyorikakar.medium.com/django-and-real-time-with-centrifugo-1da546f98ea?source=rss-4abad2f2de56------2</link>
            <guid isPermaLink="false">https://medium.com/p/1da546f98ea</guid>
            <dc:creator><![CDATA[Kakar Nyori]]></dc:creator>
            <pubDate>Mon, 18 Jan 2021 15:38:43 GMT</pubDate>
            <atom:updated>2021-07-27T15:43:40.444Z</atom:updated>
            <content:encoded><![CDATA[<p>If you ever had a doubt how to work with real-time in django…</p><p>I have used Django channels in the past for my personal projects, and it has been great for me! (I have not used it extensively so I am sorry I cannot provide any benchmarks). Channels was developed by Andrew Godwin, you might know him for his awesome work on South and django migrations.</p><blockquote>Channels use asynchronous frameworks (currently, asyncio and Twisted) to handle managing all the concurrent connections.</blockquote><p>Recently he (Andrew) had to <a href="https://groups.google.com/forum/#!topic/django-developers/mLlWYEC8_G8">leave Channels</a> for personal reasons (and he will be missed). But some awesome people have joined, to help maintain and develop Channels. Please support them if you can too.</p><p>I needed to find another simple and easy way to work with real-time in Django, just like as simple and easy Django is.</p><h3>Centrifugo</h3><blockquote>Language-agnostic real-time messaging server (Websocket and SockJS)</blockquote><p><a href="https://github.com/centrifugal/centrifugo">Centrifugo</a> was developed</p><h3>Let’s start!</h3><p>I am will be using Ubuntu 18.04 inside a <a href="https://www.vagrantup.com/">Vagrant</a> machine to work with, and have configured a private network, which allows host-only access to the machine using a specific IP (in my case 192.168.33.10).</p><h3>Virtualenvwrapper</h3><p>Let&#39;s start by first installing Virtualenvwrapper. (Please note, you might need sudo if the installation fails.)</p><pre>pip install virtualenvwrapper</pre><p>Add three lines to your shell startup file (.bashrc, .profile, etc.) to set the location where the virtual environments should live, the location of your development project directories, and the location of the script installed with this package:</p><pre>export WORKON_HOME=$HOME/.virtualenvs<br>export PROJECT_HOME=$HOME/Devel<br>source /usr/local/bin/virtualenvwrapper.sh</pre><p>After editing it, reload the startup file (e.g., run source ~/.bashrc).</p><p>Now create a virtual python environment. I will be working with python3 so I am creating a virtual environment for python3 using the -p flag:</p><pre>mkvirtualenv -p python3 djang-server</pre><p>If you get errors while this command:</p><p>ModuleNotFoundError: No module named ‘distutils.spawn’</p><p>Please install the python3 distutils package:</p><pre>sudo apt-get install python3-distutils</pre><p>And run the mkvirtualenv command again.</p><h3>Django</h3><p>After the virtual environment is created, install Django in new environment.</p><pre>pip install Django</pre><p>Now create a new Django project. (I have changed directory to the vagrant guest directory, i.e., cd /vagrant)</p><pre>django-admin.py startproject myproject</pre><p>Change directory to myproject</p><pre>cd myproject</pre><p>Let’s run the django development server to test if all is working fine (you might need sudo before the command):</p><pre>python manage.py runserver 0:80</pre><pre>Performing system checks...</pre><pre>System check identified no issues (0 silenced).</pre><pre>You have 15 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.</pre><pre>Run &#39;python manage.py migrate&#39; to apply them.</pre><pre>February 16, 2019 - 12:52:02</pre><pre>Django version 2.1.7, using settings &#39;myproject.settings&#39;</pre><pre>Starting development server at http://0:80/</pre><pre>Quit the server with CONTROL-C.</pre><p>Aha! It’s working! You can now open a new tab and go to the vagrant private IP address (in my case 192.168.33.10).</p><p>If you get an error on the page like this:</p><pre>Invalid HTTP_HOST header: ‘192.168.33.10’. You may need to add ‘192.168.33.10’ to ALLOWED_HOSTS.</pre><p>Please add the IP address in the ALLOWED_HOSTS settings:</p><pre>ALLOWED_HOSTS = [&quot;192.168.33.10&quot;]</pre><p>And refresh your page. Now you will see this successful page:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*99dUQc_WPzb_VlNsCzH4Aw.png" /></figure><p>It&#39;s working!!!</p><h4>The Chat model</h4><p>First, let’s create a chat app for our project.</p><pre>python manage.py startapp chat</pre><p>We will create two models in our chat app, i.e., Channel and Message.</p><pre>from django.db import models<br>from django.contrib import auth<br><br>User = auth.get_user_model()<br><br>class Channel(models.Model):<br>    name = models.CharField(max_length=40)<br>    is_private = models.BooleanField()<br>    users = models.ManyToManyField(User)<br><br>    def __str__(self):<br>        return self.name<br><br>class Message(models.Model):<br>    channel = models.ForeignKey(Channel, on_delete=models.CASCADE)<br>    sender = models.ForeignKey(User, on_delete=models.CASCADE)<br>    body = models.TextField()<br>    timestamp = models.DateTimeField(auto_now_add=True)<br><br>    def __str__(self):<br>        return self.body</pre><p>Register the chat app for the Django admin</p><pre>from django.contrib import admin<br>from chat.models import Channel, Message<br><br>admin.site.register(Channel)<br>admin.site.register(Message)</pre><p>Add chat app in the INSTALLED_APPS</p><pre>INSTALLED_APPS = [<br>    &#39;django.contrib.admin&#39;,<br>    ...<br>    &#39;django.contrib.staticfiles&#39;,<br>    &#39;chat.apps.ChatConfig&#39;,<br>]</pre><p>Make migrations:</p><pre>python manage.py makemigrations</pre><p>Migrate!</p><pre>python manage.py migrate</pre><p>Now let’s create a superuser for our admin</p><pre>python manage.py createsuperuser</pre><pre>Username (leave blank to use &#39;vagrant&#39;):</pre><pre>Email address: vagrant@test.com</pre><pre>Password:</pre><pre>Password (again):</pre><pre>Superuser created successfully.</pre><p>Now you can access the admin.</p><p>Let’s create channels and messages using the shell</p><pre>python manage.py shell</pre><pre>Python 3.6.7 (default, Oct 22 2018, 11:32:17)<br>[GCC 8.2.0] on linux<br>Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.<br>(InteractiveConsole)<br>&gt;&gt;&gt; from chat.models import Channel, Message<br>&gt;&gt;&gt; public_channel = Channel(name=&#39;Public channel&#39;, is_private=False) <br>&gt;&gt;&gt; public_channel.save()<br>&gt;&gt;&gt; private_channel = Channel(name=&#39;Private channel&#39;, is_private=True)<br>&gt;&gt;&gt; private_channel.save()</pre><h4>Django REST</h4><p>Install Django rest framework.</p><pre>pip install djangorestframework</pre><p>Add &#39;rest_framework&#39; to your INSTALLED_APPS setting.</p><pre>INSTALLED_APPS = (<br>    ...<br>    &#39;rest_framework&#39;,<br>)</pre><p>Add the following to your root urls.py file.</p><pre>urlpatterns = [<br>    ...<br>    url(https://medium.com/r&#39;^api-auth/&#39;,%20include(&#39;rest_framework.urls&#39;))<br>]</pre><p>Coming soon…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1da546f98ea" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Printing with Vue, Electron and Node]]></title>
            <link>https://nyorikakar.medium.com/printing-with-vue-electron-and-node-f52a730e63e7?source=rss-4abad2f2de56------2</link>
            <guid isPermaLink="false">https://medium.com/p/f52a730e63e7</guid>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[electronjs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[thermal-printer]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Kakar Nyori]]></dc:creator>
            <pubDate>Sun, 15 Dec 2019 16:41:45 GMT</pubDate>
            <atom:updated>2019-12-23T18:15:58.040Z</atom:updated>
            <content:encoded><![CDATA[<p>This is another of my post (again as a personal note for myself), how to print using a thermal printer. A similar post I posted in the past was how to print using python. However, in this post we will only work with Javascript, with special thanks to <a href="https://github.com/song940/node-escpos">node-escpos</a>!</p><p>My environment:</p><ul><li>macOS High Sierra</li><li>node v13.3.0</li><li>npm v6.13.1</li><li>node-escpos v2.5.2</li><li>The thermal printer I am using is RP 3220 star.</li></ul><p>If you get an <a href="https://github.com/song940/node-escpos/issues/214">issue</a> while installing the <a href="https://github.com/song940/node-escpos"><strong>node-escpos</strong></a> package, like I got initially, you may need to use the electron-rebuild package to fix it, which we will discuss later on.</p><h3>Lets start!</h3><p>We will start by creating a Vue project, after that we will make it an electron app, and finally install the node-escpos package to print with the thermal printer.</p><h4>Vue project</h4><p>First create a Vue project using <a href="https://cli.vuejs.org/">Vue CLI</a>. I am selecting the default options to create the project:</p><pre>vue create vue-electron-print</pre><p>After its done, lets checkout the new project</p><pre>cd vue-electron-print</pre><pre>yarn serve</pre><p>Now open the web app by visiting the URL as displayed on the terminal!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pkCl51_TgaPwefh2ZA0YLA.png" /><figcaption>Awesome web page!</figcaption></figure><p>When you are satisfied looking at your new awesome page, lets change it to bare minimum.</p><p>Edit your App.vue:</p><pre>// App.vue</pre><pre>&lt;template&gt;<br>    &lt;div id=&quot;app&quot;&gt;<br>        &lt;img alt=&quot;Vue logo&quot; src=&quot;./assets/logo.png&quot;&gt;<br>        &lt;h1&gt;Hello World!&lt;/h1&gt;<br>        &lt;p&gt;Let&#39;s print awesomeness.&lt;/p&gt;<br>        &lt;button @click=&quot;printPaper&quot;&gt;Print Paper!&lt;/button&gt;<br>    &lt;/div&gt;<br>&lt;/template&gt;<br><br>&lt;script&gt;<br>    export default {<br>        name: &#39;app&#39;,<br>        methods: {<br>            printPaper() {<br>                <strong><em>console</em></strong>.log(&#39;printPaper!&#39;)<br>            }<br>        }<br>    }<br>&lt;/script&gt;<br><br>&lt;style&gt;<br>    #app {<br>        text-align: center;<br>        color: #2c3e50;<br>        margin-top: 60px;<br>    }<br>&lt;/style&gt;</pre><p>Which will look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F51mh6hbrIBz6V-aIBsfYw.png" /><figcaption>Awesome web page!</figcaption></figure><h4>Electron app</h4><p>Now that it’s upto bare minimum, let’s add electron to our awesome project using a very easy and clean plugin… <a href="https://nklayman.github.io/vue-cli-plugin-electron-builder/">Vue CLI Plugin Electron Builder</a>! It will add a new background.js file to your project folder, that is required for the electron app. I will be using the latest electron for this tutorial, which as of date for this plugin is v6.0.0.</p><pre>vue add electron-builder</pre><p>To start the development server run this command, and you will see your electron app pop up!</p><pre>yarn electron:serve</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x7LRjR1hIVkN5wuXFguOdw.png" /></figure><h4>Print print print!</h4><p>Now that we are out of the browser specific limited world, we can utilise the true power of Node.js with our electron app.</p><p>Install the package responsible to print via thermal printer</p><pre>npm i escpos --save</pre><p>You might get this errors:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HXz6857ILYhGoUO7LLQzAQ.png" /></figure><p>But we can continue and import the package to test the node-escpos package.</p><p>Edit your background.js:</p><pre>...<br>const escpos = require(&#39;escpos&#39;);<br>...<br>...<br>...<br>setTimeout(() =&gt; {<br>  <strong><em>console</em></strong>.log(&#39;test print start&#39;)<br><br>  // Select the adapter based on your printer type<br>  const device  = new escpos.USB();<br>// const device  = new escpos.Network(&#39;localhost&#39;);<br>// const device  = new escpos.Serial(&#39;/dev/usb/lp0&#39;);<br><br>  const options = { encoding: &quot;GB18030&quot; /* default */ }<br>// encoding is optional<br><br>  const printer = new escpos.Printer(device, options);<br><br><br><br>  device.open(function(){<br>    printer<br>        .font(&#39;a&#39;)<br>        .align(&#39;ct&#39;)<br>        .style(&#39;bu&#39;)<br>        .size(1, 1)<br>        .text(&#39;The quick brown fox jumps over the lazy dog&#39;)<br>        .text(&#39;敏捷的棕色狐狸跳过懒狗&#39;)<br>        .barcode(&#39;1234567&#39;, &#39;EAN8&#39;)<br>        .table([&quot;One&quot;, &quot;Two&quot;, &quot;Three&quot;])<br>        .tableCustom([<br>          { text:&quot;Left&quot;, align:&quot;LEFT&quot;, width:0.33 },<br>          { text:&quot;Center&quot;, align:&quot;CENTER&quot;, width:0.33},<br>          { text:&quot;Right&quot;, align:&quot;RIGHT&quot;, width:0.33 }<br>        ])<br>        .qrimage(&#39;https://github.com/song940/node-escpos&#39;, function(err){<br>          this.cut();<br>          this.close();<br>        });<br>  });<br>  <br>  <strong><em>console</em></strong>.log(&#39;test print end&#39;)<br>}, 3000)</pre><p>And again run the electron app:</p><pre>yarn electron:serve</pre><p>Again you might get this error:</p><pre>ERROR Failed to compile with 1 errors 8:00:53 PM</pre><pre>This dependency was not found:</pre><pre>* node-bluetooth in ./node_modules/escpos/adapter/bluetooth.js</pre><pre>To install it, you can run: npm install — save node-bluetooth<br> ERROR Build failed with errors.<br>error Command failed with exit code 1.</pre><p>Let’s continue however, and if not then create a new vue.config.js file in the root directory, and add these to the file:</p><pre>module.exports = {<br>    pluginOptions: {<br>        electronBuilder: {<br>            // List native deps here if they don&#39;t work<br>            externals: [&#39;escpos&#39;],<br>            // If you are using Yarn Workspaces, you may have multiple node_modules folders<br>            // List them all here so that VCP Electron Builder can find them<br>            nodeModulesPath: []<br>        }<br>    }<br>}</pre><p>And again run the app, and this time you will get this error:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d6blGTqIw3Syl8AKwhRGwQ.png" /></figure><p>Now, there are some more work to be done, as answered in this <a href="https://stackoverflow.com/questions/46384591/node-was-compiled-against-a-different-node-js-version-using-node-module-versio/52796884#52796884">Stackoverflow post</a>:</p><ol><li>Require all dependencies you need in the main.js file that is run by electron. (we have done this already.)</li><li>Run npm i -D electron-rebuild to add the <a href="https://github.com/electron/electron-rebuild">electron-rebuild</a> package.</li><li>Remove the node-modules folder, as well as the packages-lock.json file.</li><li>Run npm i to install all modules.</li><li>Run ./node_modules/.bin/electron-rebuild to rebuild everything</li></ol><p>Now let’s run the app!</p><pre>yarn electron:serve</pre><blockquote>Lo and behold!!! The app is <strong><em>running</em></strong> and also it’s<strong><em> printing</em></strong>!</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*69WnRx8zGMnYRkvxFB0gqQ.png" /><figcaption>Also, notice the awesome console msg! 😊</figcaption></figure><p>You might also be getting these errors, “Could not find a package.json for …”:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hn3DX7_xvlq-vhS5Jh-dfw.png" /></figure><p>For that, we will have to remove nodeModulesPath from vue.config.js as we don’t need to set that configuration. So this is the final vue.config.js:</p><pre>module.exports = {<br>    pluginOptions: {<br>        electronBuilder: {<br>            externals: [&#39;escpos&#39;],<br>        }<br>    }<br>}</pre><p>Now let’s clean up our background.js and move all the node-escpos code to App.vue also update our code:</p><pre>// App.vue</pre><pre>...</pre><pre>...<br>&lt;script&gt;<br>    import escpos from &#39;escpos&#39;<br><br>    export default {<br>        name: &#39;app&#39;,<br>        methods: {<br>            printPaper() {<br>                <strong><em>console</em></strong>.log(&#39;printPaper! start&#39;)<br>                const device = new escpos.USB();<br>                const options = {encoding: &quot;GB18030&quot; /* default */}<br>                const printer = new escpos.Printer(device, options);<br><br>                device.open(function () {<br>                    printer<br>                        .font(&#39;a&#39;)<br>                        .align(&#39;ct&#39;)<br>                        .style(&#39;bu&#39;)<br>                        .size(1, 1)<br>                        .text(&#39;Hello world!&#39;)<br>                        .text(&#39;Welcome to the Awesome-land!!!&#39;)<br>                        .cut()<br>                        .close()<br>                });<br>                <strong><em>console</em></strong>.log(&#39;printPaper! end&#39;)<br>            }<br>        }<br>    }<br>&lt;/script&gt;<br>...<br>...</pre><p>Run your app! And if you click the <strong>Print Paper</strong> button, you will have yourself a printed version of <strong><em>awesomeness</em></strong>!</p><p>That’s all for now! I will see you when I see you! 🤗</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f52a730e63e7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Printing with Python and Epson POS printer.]]></title>
            <link>https://nyorikakar.medium.com/printing-with-python-and-epson-pos-printer-fbd17e127b6c?source=rss-4abad2f2de56------2</link>
            <guid isPermaLink="false">https://medium.com/p/fbd17e127b6c</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[pos-printer]]></category>
            <dc:creator><![CDATA[Kakar Nyori]]></dc:creator>
            <pubDate>Fri, 16 Nov 2018 11:29:40 GMT</pubDate>
            <atom:updated>2018-11-21T05:24:11.345Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CNDDPJKxpukj8VRVX59MqA.jpeg" /></figure><p>This post is for my future self. I am trying to print using a python package on windows, called <a href="https://github.com/python-escpos/python-escpos">python-escpos</a>. This library works fine in both mac and Unix by just installing the library and some of its additional dependencies such as <strong>lsusb</strong>. However, on windows, you need extra steps to work. So I will be posting any new developments, trials, updates in this post and hopefully I will be able to work out this library on windows OS. This post is/will be in draft mode, and will be published only when I will be able to print with python and the Epson printer on windows.</p><p>Let&#39;s begin!</p><p>Prerequisites:</p><ol><li>Windows OS. I am using windows 7 (64 bit).</li><li>Python and pip. I am using python 2.7.15 (64 bit)</li><li>Virtualenvwrapper (optional)</li><li>Install the printer drivers (restart if need be).</li></ol><p>Start by installing python-escpos using pip:</p><pre>pip install python-escpos --pre</pre><p>At the time of writing this story, I am using a pre-release version of python-escpos (v3.0a4). So, please be sure to refer to the correct version of the documentation, as there are major changes in different versions.</p><p>Now after you have installed the library, you can check whether it is working by running the following command as <a href="https://python-escpos.readthedocs.io/en/latest/user/usage.html#define-your-instance">documented</a>, also as one of the maintainers answered on <a href="https://stackoverflow.com/questions/38785335/typeerror-item-in-from-list-not-a-string-for-escops">StackOverflow</a>:</p><pre>from escpos.printer import Usb<br>Epson = Usb(0x04b8,0x0202)</pre><p>But you will get an error:</p><blockquote>usb.core.NoBackendError: No backend available</blockquote><p>I went through many searches regarding this issue.</p><ol><li><a href="https://github.com/python-escpos/python-escpos/issues/299">https://github.com/python-escpos/python-escpos/issues/299</a></li><li><a href="https://github.com/python-escpos/python-escpos/pull/274">https://github.com/python-escpos/python-escpos/pull/274</a></li><li><a href="https://github.com/libusb/libusb/issues/85">https://github.com/libusb/libusb/issues/85</a></li></ol><p>After some digging around, I found this <a href="https://github.com/libusb/libusb/wiki/Windows">wiki</a>. According to this, I had to use the most recent version of Zadig, an Automated Driver Installer GUI application for WinUSB, libusb-win32 and libusbK. Also, this answer on <a href="https://stackoverflow.com/questions/31960314/pyusb-1-0-notimplementederror-operation-not-supported-or-unimplemented-on-this">StackOverflow</a> basically says the same thing.</p><p>So, I downloaded Zadig, opened the application, and searched for my printer from the drop-down menu. However, it was not listed on the list. Later I found out, inside the Options menu you can enable “List All Devices”. After I have checked in the option to list all devices, from the drop-down menu, I selected TM-82, and chose WinUSB to replace/install the driver successfully.</p><blockquote>Note: If you get an error and you try to reinstall the driver, you will get another error. You can try to delete the <strong><em>usb_driver</em></strong> directory from the <strong><em>user</em></strong> directory and try to install again. Also you can confirm by going to your Device manager.</blockquote><p>After that again I ran the same python-escpos commands as documented, and got the same error:</p><blockquote><em>usb.core.NoBackendError: No backend available</em></blockquote><p>Again I had to continue my search for the light, and I went through many more searches</p><ol><li><a href="https://github.com/python-escpos/python-escpos/issues/306">https://github.com/python-escpos/python-escpos/issues/306</a></li><li>Finally, I landed on this issue, <a href="https://github.com/pyusb/pyusb/issues/120">https://github.com/pyusb/pyusb/issues/120</a></li><li>Which in turn led me to many StackOverflow issue. Tried many of answers, and lastly, this post helped me <a href="https://stackoverflow.com/questions/33972145/pyusb-on-windows-8-1-no-backend-available-how-to-install-libusb/34720024#34720024">https://stackoverflow.com/questions/33972145/pyusb-on-windows-8-1-no-backend-available-how-to-install-libusb/34720024#34720024</a></li></ol><p>So according to the above answer on the StackOverflow, this is what I did:</p><ol><li>I downloaded the libusb library from <a href="http://sourceforge.net/projects/libusb/files/libusb-1.0/libusb-1.0.20/libusb-1.0.20.7z/download">http://sourceforge.net/projects/libusb/files/libusb-1.0/libusb-1.0.20/libusb-1.0.20.7z/download</a></li><li>Extracted the files</li><li>Copied libusb-1.0.dll into my windows system directory.</li></ol><ul><li>On 64-bit Windows:<br>MS64\dll\libusb-1.0.dll must be copied into C:\Windows\System32</li><li>On 32-bit windows:<br>MS32\dll\libusb-1.0.dll must be copied into C:\Windows\SysWOW64.</li></ul><p>4. Copied libusb-1.0.lib from binaries to lib dir into the python directory <br>i.e., Copy MS64\static\libusb-1.0.lib to C:\Users\user\Envs\py3env\Lib or Copy MS32\static\libusb-1.0.lib to C:\Users\user\Envs\py3env\Lib</p><p>Now when I run the above python-escpos command, I get a different error:</p><pre>from escpos import *<br>Epson = printer.Usb(0x04b8,0x0202)</pre><blockquote>raise USBNotFoundError(“Device not found or cable not plugged in.”)</blockquote><p>Since I am not getting NoBackendError error, I hope it will work when I connect an Epson POS printer. I will get back after I have tested with the printer.</p><p>Alright, I am back, and after I have connected the printer, I am getting a different error:</p><blockquote>Could not set configuration: {0}</blockquote><p>So, I searched for the light again, and as it turns out I needed to restart my computer after the driver installation.</p><p>Now when I run the command, I am getting back the old error:</p><blockquote><em>usb.core.NoBackendError: No backend available</em></blockquote><p>So, I searched for the light again and searched through many more posts over the ocean of internet! I also went through a pyusb tutorial to check whether the issue is with pyusb (a library dependency of python-escpos). But while going through the <a href="https://github.com/pyusb/pyusb/blob/master/docs/tutorial.rst">pyusb tutorial</a>, pyusb found the printer, as the following command didn’t throw any errors at me.</p><pre>import usb.core<br><br># find our device<br>dev = usb.core.find(idVendor=0xfffe, idProduct=0x0001)<br><br># was it found?<br>if dev is None:<br>    raise ValueError(&#39;Device not found&#39;)</pre><p>So, the problem is not with the <strong><em>pyusb </em></strong>or <strong><em>libusb</em></strong>. The problem was with the <strong><em>python-escpos</em></strong> library.</p><p>Finally, I landed on this <a href="https://stackoverflow.com/questions/41853951/pyusb-on-windows-7-notimplemented-error-is-kernal-driver-active">StackOverflow answer</a>:</p><blockquote>The problem is plain and simple that the check whether a kernel driver is active which is not possible on Windows. It seems this library is simply not written for use on Windows.</blockquote><blockquote>You can use it on Windows if you delete the last 5 lines from the source code starting with if self.device.is_kernel_driver_active(0): or check if the code runs on Windows beforehand and don&#39;t call them.</blockquote><p>So, what I did was, I commented out the following lines from the <strong><em>printer.py</em></strong> module of python-escpos library from the site-packages inside my virtual environment</p><pre>try:<br>    check_driver = self.device.is_kernel_driver_active(0)<br>except NotImplementedError:<br>    pass</pre><pre>if check_driver is None or check_driver:<br>    try:<br>        self.device.detach_kernel_driver(0)<br>    except usb.core.USBError as e:<br>        if check_driver is not None:<br>            print(&quot;Could not detatch kernel driver: {0}&quot;.format(str(e)))</pre><p>And now, when I run the above command as documented, I get my printer and can run the python-escpos commands to print!!!</p><blockquote>Note: This has been tested on both Windows 7 and windows 10</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fbd17e127b6c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Starting with GeoDjango]]></title>
            <link>https://nyorikakar.medium.com/starting-with-geodjango-50de5ba00ec8?source=rss-4abad2f2de56------2</link>
            <guid isPermaLink="false">https://medium.com/p/50de5ba00ec8</guid>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Kakar Nyori]]></dc:creator>
            <pubDate>Sun, 26 Aug 2018 07:06:04 GMT</pubDate>
            <atom:updated>2018-08-26T09:23:55.207Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cm-cuSm0fyMm_PDyPfAz9w.jpeg" /><figcaption>Earth vector designed by <a href="https://www.vecteezy.com/">vecteezy.com</a></figcaption></figure><p>This is another post for my future reference. In the meantime if this post helped you too, then I am glad I was of some help.</p><h4>Prerequisites</h4><ul><li>Ubuntu 18.04 server. I am using a vagrant machine running on my mac book pro.</li><li>Set up the server for Django development workflow. Make sure to follow this post on how to <a href="https://medium.com/@nyorikakar/preparing-django-development-in-a-new-ubuntu-server-62626aafbbbc">prepare Django development on an Ubuntu server</a>.</li></ul><h4>Lets start!</h4><p>On Debian/Ubuntu, you are advised to install the following packages which will install, directly or by dependency, the required geospatial libraries:</p><pre>$ sudo apt-get install binutils libproj-dev gdal-bin</pre><p>I will be using PostgreSQL database instead of using the default SQLite database. So lets install PostgreSQL and its additional packages into our server</p><pre>$ sudo apt-get install postgresql postgresql-contrib</pre><p>Also, we need to install <a href="http://initd.org/psycopg/">psycopg2</a> module, the PostgreSQL database adapter for our Django app. Please remember to install the module in the virtual environment.</p><pre>pip install psycopg2</pre><p>During the Postgres installation, an operating system user named postgres was created to correspond to the postgres PostgreSQL administrative user. We need to use this user to perform administrative tasks. We can use sudo and pass in the username with the -u option.</p><p>Log into an interactive Postgres session by typing:</p><pre>sudo -u postgres psql</pre><p>You will be given a PostgreSQL prompt where we can set up our requirements.</p><p>First, create a database for your project:</p><pre>postgres=# CREATE DATABASE geo_django_db;</pre><p>Next, create a database user for our project. Make sure to select a secure password:</p><pre>postgres=# CREATE USER myprojectuser WITH PASSWORD &#39;mystrongpassword&#39;;</pre><h4>Creating a spatial database</h4><p>PostGIS 2 includes an extension for PostgreSQL that’s used to enable spatial functionality. Lets switch to the newly created database and enable the spatial functionality:</p><pre>postgres=# \c geo_django_db<br>geo_django_db=# CREATE EXTENSION postgis;</pre><h4>Note:</h4><p>If you get an error saying:</p><blockquote>ERROR: could not open extension control file “/usr/share/postgresql/10/extension/postgis.control”: No such file or directory</blockquote><p>Run this command:</p><pre>sudo apt-get install postgis</pre><p>After it has finished, again connect to your database. And retry to enable the spatial functionality.</p><h4>Note:</h4><p>If you are on a vagrant machine, and you get an error saying:</p><pre>psql: FATAL: role “vagrant” does not exist</pre><p>You need to give vagrant superuser access.</p><pre>sudo su - postgres<br>createuser vagrant -s<br>exit  # exit from postgres user back into vagrant</pre><p>After the extension was successful, exit out of the PostgreSQL prompt by typing:</p><p>\q</p><h4>Django project</h4><p>Use the standard django-admin script to create a new project</p><pre>django-admin startproject geo_project</pre><p>In your Django project, edit this changes into the settings.py. You can leave the PORT setting as an empty string or enter the port to connect your database:</p><pre>DATABASES = {<br>    &#39;default&#39;: {<br>        &#39;ENGINE&#39;: &#39;django.contrib.gis.db.backends.postgis&#39;,<br>        &#39;NAME&#39;: &#39;geo_django_db&#39;,<br>        &#39;USER&#39;: &#39;myprojectuser&#39;,<br>        &#39;PASSWORD&#39;: &#39;mystrongpassword&#39;,<br>        &#39;HOST&#39;: &#39;localhost&#39;,<br>        &#39;PORT&#39;: &#39;&#39;,<br>    },<br>}</pre><p>In addition, modify the INSTALLED_APPS setting to include django.contrib.admin and django.contrib.gis:</p><pre>INSTALLED_APPS = [<br>    &#39;django.contrib.admin&#39;,<br>    &#39;django.contrib.auth&#39;,<br>    &#39;django.contrib.contenttypes&#39;,<br>    &#39;django.contrib.sessions&#39;,<br>    &#39;django.contrib.messages&#39;,<br>    &#39;django.contrib.staticfiles&#39;,<br>    &#39;django.contrib.gis&#39;,<br>]</pre><p>And that’s it! Hoping to see you soon!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=50de5ba00ec8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Preparing Django development on an Ubuntu server]]></title>
            <link>https://nyorikakar.medium.com/preparing-django-development-in-a-new-ubuntu-server-62626aafbbbc?source=rss-4abad2f2de56------2</link>
            <guid isPermaLink="false">https://medium.com/p/62626aafbbbc</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[django]]></category>
            <dc:creator><![CDATA[Kakar Nyori]]></dc:creator>
            <pubDate>Sat, 25 Aug 2018 17:58:42 GMT</pubDate>
            <atom:updated>2018-08-26T06:05:17.116Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9DCN5Fzks6Q5bd2sjtM8LA.jpeg" /></figure><p>This is not a tutorial per se, rather a reference for my future self. This is how I always start when I am developing a new app in Django. In the meantime if this post was helpful to you, then I am glad I was of some help.</p><p>Lets start!</p><p>I will be using Ubuntu 18.4. We will first update the apt package list.</p><p>$ sudo apt-get update</p><p>We will be using Python package manager pip to install python packages in the future, so we need to install it.</p><p>$ sudo apt-get install python-pip</p><p>Finally, create a virtual environment with the help of <a href="https://virtualenvwrapper.readthedocs.io/en/latest/">Virtualenvwrapper</a>, for managing development workflow, making it easier to work on more than one project at a time without introducing conflicts in their dependencies.</p><p>Install virtualenvwrapper. If you are not the super user, you might need to include sudo.</p><p>$ pip install virtualenvwrapper</p><p>Add three lines to your shell startup file (.bashrc, .profile, etc.) to set the location where the virtual environments should live, the location of your development project directories, and the location of the script installed with this package:</p><pre>export WORKON_HOME=$HOME/.virtualenvs<br>export PROJECT_HOME=$HOME/Devel<br>source /usr/local/bin/virtualenvwrapper.sh</pre><p>After editing it, reload the startup file (e.g., run source ~/.bashrc).</p><p>Now, create a virtual environment</p><pre>$ mkvirtualenv -p python3 testenv</pre><p>The -p flag is to specify which python version to use with the above environment.</p><h4>Note:</h4><p>If you get an error, saying</p><blockquote>ModuleNotFoundError: No module named ‘distutils.spawn’</blockquote><p>Install the required package. And again try to create the virtual environment.</p><pre>sudo apt-get install python3-distutils</pre><p>After the virtual environment has been successfully created, it will automatically be activated.</p><p>You can deactivate from the virtual environment by running this command:</p><p>$ deactivate</p><p>To view your virtual environment lists, use the workon command:</p><p>$ workon</p><p>To activate a virtual environment, use the workon command followed by the environment name. Example:</p><p>$ workon testenv</p><p>After the virtual environment is activated, install python packages into the virtual environment.</p><p>$ pip install Django</p><p>Lets create a new Django project</p><pre>django-admin startproject myproject</pre><p>If you need to remove a virtual environment use the rmvirtualenv command followed by the environment name. Example:</p><pre>rmvirtualenv testenv</pre><p>And this is it! See you soon.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=62626aafbbbc" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>