Giter Club home page Giter Club logo

htmx-alpine-crud's Introduction

W4-Task

with CRUD oprations on Blog model

Routes

by using Django-Ninja, i create a 4-routes for the CRUD oprations, by using schemas to validata the payload and parse the response in it, and the Router to provide an access to each endpoints

Schema

  1. blog.py:
from ninja import Schema

class BlogSchema(Schema):
    id: int
    title: str
    description: str


class BlogIn(Schema):
    title: str
    description: str
  1. response:
from ninja import Schema

class MessageSchema(Schema):
    message: str

templates

  1. i create table_form.html table.html,and table_row.html for design the page.
  2. in /partials/ i update in table_opereations by adding:
    • get_blogs: The Main Function that incude all below methods:
      • init(): To fetch the blogs and put it in the table
      • create_blog: with Two Vars (Title, description) That Binding with form field, and return async function (add_blog)
      • delete_blog: That recive Blog.id and send it as params to delete it
      • update_blog: That recive Blog.id and send it as a payload

Note

in Alpine code, i check if the response is success or not depending on message i sent from the backend with the response schema, cause i didn't know how to access status code (cause it is my first time in django- ninja) so the code become:

if (response.message === "Ok"){
    this.msg = 'deleted'
}
else{
    this.error_msg = 'there was an error !!'
}

i try :

if (response.status >= 200 && response.status < 300){
    this.msg = 'deleted'
}

and

if (response.statusCode >= 200 && response.statusCode < 300){
    this.msg = 'deleted'
}

but both of it return undefind

htmx-alpine-crud's People

Contributors

movy18x avatar bqbb 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.