Skip to content

Instantly share code, notes, and snippets.

View Shrestha7's full-sized avatar
:octocat:
Working from home

Swastik Shrestha Shrestha7

:octocat:
Working from home
View GitHub Profile
@Shrestha7
Shrestha7 / .gitignore
Created September 16, 2020 01:33
Django gitignore file
# Created by .ignore support plugin (hsz.mobi)
### Django-gitignore ultimate template
### Django ###
*.log
*.pot
*.pyc
__pycache__/
local_settings.py
db.sqlite3
db.sqlite3-journal
@Shrestha7
Shrestha7 / admin.py
Last active November 13, 2020 07:00
Django crud with ajax
from django.contrib import admin
from .models import Book
admin.site.register(Book)
@Shrestha7
Shrestha7 / base.html
Created November 13, 2020 07:08
Django crud with ajax part 1
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bookstore</title>
<link href="{% static 'css/bootstrap.min.css' %}" rel="stylesheet">
</head>
@Shrestha7
Shrestha7 / book_create.html
Created November 13, 2020 07:12
Django crud with ajax create part 2
{% load crispy_forms_tags %}
<form method="post" data-url="{% url 'book_create' %}" class="create-form">
{% csrf_token %}
<div class="modal-header">
<h5 class="modal-title" >Create Book</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
@Shrestha7
Shrestha7 / book_list.html
Created November 13, 2020 08:14
Django crud with ajax update part 3
{% extends 'base.html' %}
{% block content %}
<h1 class="page-header">Books</h1>
<button class="btn btn-primary show-form" data-url="{% url 'book_create' %}">
<span class="glyphicon glyphicon-plus"></span>
New Book
</button>
<table class="table" id="book-table">
<thead>
@Shrestha7
Shrestha7 / book_delete.html
Created November 13, 2020 08:18
Django crud with ajax delete part 4
{% load crispy_forms_tags %}
<form method="post" data-url="{% url 'book_delete' book.id %}" class="delete-form">
{% csrf_token %}
<div class="modal-header">
<h5 class="modal-title" >Delete Book</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
@Shrestha7
Shrestha7 / models.py
Created October 18, 2021 08:58
listing the path of directory templates
from pathlib import Path
from typing import Reversible
from django.db import models
from os import listdir
from os.path import isfile, join
import os
# Create your models here.
class insp(models.Model):
@Shrestha7
Shrestha7 / models.py
Created October 19, 2021 11:32
file handling in models
from pathlib import Path
from typing import Reversible
from django.db import models
from os import listdir, path
from os.path import isfile, join
import os
import glob
# Create your models here.
class insp(models.Model):
@Shrestha7
Shrestha7 / consumeapi.py
Last active February 23, 2022 01:54
consume api in python
import requests
import pprint
url='https://'
response = request.get(url)
pprint.pprint(response.json())