Code Monkey home page Code Monkey logo

djangobackendtutorial's Introduction

DjangoBackendTutorial

This is a basic introduction to the Django Rest Framework. I've posted this here so I can easily refer to it accross machines. Note that I am running this on Linux Ubuntu 18.04 LTS. Note that I did not create this tutorial, I am have simply gone through it and found it to be a particularly useful beginner guide and posted here for convenience sake. The original tutorial can be found at Django for React/Angular/Mobile Apps

Following the steps below, you should be able to reproduce the below screenshot on your machine:

django

Setup Backend

clone the repositroy:-

git clone https://github.com/vinitraj10/Django-React-Blog 

Create Virtualenv for django:-

virtualenv -p python3 mobileBackend && cd mobileBackend

Activate Virtual env:-

source bin/activate

Install Djangorestframework:-

pip install django djangorestframework

Make Migrations:-

./manage.py makemigrations
./manage.py migrate

Enter Objects Into Database

Open the shell

python manage.py shell

Enter actors into our SQLite database

from actors.models import Actor
actor1 = Actor(
first_name="Tom",
last_name="Cruise",
dp="https://ia.media-imdb.com/images/M/MV5BMTk1MjM3NTU5M15BMl5BanBnXkFtZTcwMTMyMjAyMg@@._V1_UY317_CR14,0,214,317_AL_.jpg",
age=55
)
actor1.save()
actor2 = Actor(
first_name="Hugh",
last_name="Jackman",
dp="https://images-na.ssl-images-amazon.com/images/M/MV5BNDExMzIzNjk3Nl5BMl5BanBnXkFtZTcwOTE4NDU5OA@@._V1_UX214_CR0,0,214,317_AL_.jpg",
age=49
)
actor2.save()

Verify the entries

Actor.objects.all()

This should give the following output:

<QuerySet [<Actor: Actor object (1)>, <Actor: Actor object (2)>]>

Run Server

Start server for your REST-API:-

./manage.py runserver

View in Browser

enter http://localhost:8000 in your browser window

djangobackendtutorial's People

Contributors

akirademoss avatar

Watchers

 avatar

djangobackendtutorial's Issues

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.