Giter VIP home page Giter VIP logo

wdc-class-2-coinmarketcap-auth's Introduction

Coinmarketcap auth

Remember the https://coinmarketcap.com/ clone we did in our previous class? ๐Ÿ’ช Today we will augment it with some authentication capabilities. ๐Ÿ™Œ

We want users to be able to log in and log out from the app, using the built-in Django authentication views. Check the official documentation for extra details: https://docs.djangoproject.com/en/2.0/topics/auth/default/

1) Adding log in and log out views

There's no need to implement the log in and log out features, Django comes with it out of the box. Just set the proper URLs, and add the link in your navbar like this:

image

The view will look by default for a template called templates/registration/login.html. Just create a template with that name, and give it the styles you want. It should look something like this:

image

For the log out view, you won't need any template. Just point the link to the URL you configured in your utls.py module, and that's it.

2) Creating new coins

As a second step, we want the users of our app to be able to create new Cryptocurrencies. For that we need to create a custom Django ModelForm, which will handle all the fields validation for us, according to the rules configured in the Cryptocurrency model.

Add a button in the main page, with a link to /create. Should look something like:

image

In the /create template, we will render a form with only a few of the required models to create a Cryptocurrency object. Check the following screenshot for extra details:

image

The ModelForm will handle all the fields validation, but you will need to show errors in the template properly if they are present.

hint: check the django-bootstrap4 library for easy integration of Bootstramp v4 in templates

3) Let's practice some foreign relationships between models.

We want to add a new FavouriteCoin model. It will have two new ForeignKey fields, one pointing to User and one to Cryptocurrency. Once you have the code in models.py, make sure to create the needed migrations.

If you are done, open the Django Shel (run django-admin shell command), and play with the new model, creating or fetching them from the DB.

That's all! ๐ŸŽ‰ We just did a second iteration to the Coinmarketcap clone, adding some more advanced functionalities of the Django framework.

wdc-class-2-coinmarketcap-auth's People

Contributors

santiagobasulto avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.