I hereby claim:
- I am shaurya-blip on github.
- I am sblipdev (https://keybase.io/sblipdev) on keybase.
- I have a public key ASChL-n6owvUHN6DHVTnBiyfkQDOkUStcFKnNUZ51tWm2Ao
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
# Coefficients | |
print('Coefficients: \n', regressor.coef_) | |
# The mean squared error | |
print("Mean squared error: %.2f" % np.mean((regressor.predict(X_test) - y_test) ** 2)) | |
# Explained variance score: 1 is perfect prediction | |
print('Variance score: %.2f' % regressor.score(X_test, y_test)) |
DATABASES = { | |
'default': { | |
'ENGINE': 'django.db.backends.postgresql_psycopg2', | |
'NAME': 'sample', # DATABASE NAME | |
'USER': 'postgres', # NAME OF USER (DEFAULT IS postgres) | |
'PASSWORD': 'xyz', # whatever password you have kept. | |
'HOST': '127.0.0.1', # HOST in which the psql server is running on | |
'PORT': '5432', # PORT in which the psql server is running on | |
} | |
} |
import requests | |
def create_book(title, author): | |
headers={ | |
'title':title, | |
'author':author | |
} | |
response = requests.post('http://127.0.0.1:8000/books/', headers) | |
print(f"New book {title} by {author} has been created,\n\n") |
from django.urls import include, path | |
from rest_framework import routers | |
from .views import BookViewSet | |
router = routers.DefaultRouter() | |
router.register(r'books', BookViewSet) | |
urlpatterns = [ | |
path('', include(router.urls)), |
"""Books URL Configuration | |
The `urlpatterns` list routes URLs to views. For more information please see: | |
https://docs.djangoproject.com/en/3.0/topics/http/urls/ | |
Examples: | |
Function views | |
1. Add an import: from my_app import views | |
2. Add a URL to urlpatterns: path('', views.home, name='home') | |
Class-based views | |
1. Add an import: from other_app.views import Home |
from rest_framework import viewsets | |
from .serializer import BookModelSerializer | |
from main.models import Book | |
class BookViewSet(viewsets.ModelViewSet): | |
queryset = Book.objects.all() | |
serializer_class = BookModelSerializer |
from rest_framework import serializers | |
from main.models import Book | |
class BookModelSerializer(serializers.ModelSerializer): | |
class Meta: | |
model = Book | |
fields = '__all__' | |
INSTALLED_APPS = [ | |
'main', | |
... | |
'rest_framework' | |
] |
from django.contrib import admin | |
from .models import Book | |
# Register your models here. | |
admin.site.register(Book) |