How to install
Unicorn and create a basic component.
Hello! Welcome to the very first screencast for Unicorn, the magical full-stack framework for Django.
In this episode I'll show you how to install Unicorn and create a basic component. You can see I just created a brand new Django project and we can see the fancy rocketship getting ready to blast off!
So, let's look at the code.
I already added a "www" app to have a simple index page to put our components on.
poetry to install Python packages, but of course installing with
pip will work just fine as well.
Ok! So, the library is installed. There are two steps to start using it in Django.
First, add "django_unicorn" to the
INSTALLED_APPS in your settings file.
Second, add the url route.
Now, Unicorn is integrated with Django. Let's create a new component to see how it all works. Built into Unicorn is a Django management command to create new components. Let's create a new component to track magical creature sightings.
Awesome! So, we have a component. Now what?! For our first component, we need to tell Django where to look for templates. Let's register the "unicorn" folder that just got created in
Alright, now we can start integrating that new component we created earlier into our template.
We'll need to load the Unicorn template tags so they can be used later on.
Make sure that the Django CSRF tokens are available because they will protect us from cross-site scripting attacks.
And finally, our new component!
Let's update the "sighting" component and refresh the page and voila! we now have a more complicated Django "includes" templatetag. :)
But, now is where things get more fun!
Let's add a textbox on our component to count how many times we've seen a magical creature.
And that wraps up the first screencast on how to install Unicorn!