GithubHelp home page GithubHelp logo

app-generator / api-server-django Goto Github PK

View Code? Open in Web Editor NEW
41.0 3.0 15.0 104 KB

Django API Server - Open-Source API Server | AppSeed

Home Page: https://appseed.us/boilerplate-code/django-boilerplate/

License: Other

Python 98.11% Dockerfile 1.43% Shell 0.46%
django-rest-framework appseed-sample django-api django-api-framework django-oauth python-api django-api-oauth django-api-sample django-api-server python-django-api

api-server-django's Introduction

The New version of AppSeed - Generate Digital Products, Update legacy code by chat, Inject new modules, Software Auto-healing, AI, Deployment automation (any provider), Docker, K8s.

๐Ÿ‘‰ LIVE Demo: https://app-generator.dev


Features

  • One-Click Sign IN: GitHub
  • Marketplace: mirrored from AppSeed
  • Generator (CLI & Web Versions)
    • MVC: Django, NodeJS, Flask, FastAPI
    • Full-Stack: React, Vue with any API Backend
    • API [ manage visually the data ]
    • eCommerce
    • Website
  • Deployment options: Render, AppSeed Cloud Digital Ocean, User Provider (AWS, DO, Azure)
  • Developer Tools
    • AI introspection to different data sources
    • CSV processing and data extraction
    • CSV to model
  • Sections:

SPECS


For more input please contact support using the following:


Stack

  • Python/Django
  • React
  • Docker
  • CI/CD - LIVE Deploy on Digital Ocean

Manual Build

Download the code

$ git clone https://github.com/app-generator/appseed-v2.git
$ cd appseed-v2

Install modules via VENV

$ virtualenv env
$ source env/bin/activate
$ pip install -r requirements.txt

Set Up Database

$ python manage.py makemigrations
$ python manage.py migrate

Start the APP

$ python manage.py createsuperuser # create the admin
$ python manage.py runserver       # start the project
$ python manage.py runsslserver    # SSL Mode [ https://localhost:8000 ]

At this point, the app runs at http://127.0.0.1:8000/.


CLI Interface

Generate Code

For now, only Django code is supported.

$ python manage.py generator -i # Print HELP 
$ python manage.py generator -f sources/input-template-volt.json

The generated code is saved in generated_code DIR. Open the sources using your favorite editor and start the project. The easier way is to use Docker:

$ cd generated_code/GENERATED_PROJECT/
$ docker-compose up --build

Wait for Docker completion and visit http://localhost:5085 in the browser.


Upload project to GitHub

Note: For having SUCCESS on this operation, a GITHUB_KEY is required - read more.

$ python manage.py github -i # Print HELP 
$ python manage.py github -d generated_code/GENERATED_PROJECT/ -k GITHUB_KEY

Once the operation is finished, the generated project should be saved under the account associated with the GITHUB_KEY.


Compile DOCS

The Documentation being generated by , the compilation requires a linux box

$ cd docs && rm -rf build && make html
# Or via a while loop
$ cd docs ; while true ; do rm -rf build/ ; make html ; sleep 10 ; done

The output is saved on docs/build and rendered on /docs/ URI


Celery (async tasks)

  • Make sure you have a Redis Server running: redis://localhost:6379
    • $ redis-cli and type ping
  • In the base directory inside tasks_scripts folder you need to write your scripts file.
  • Run the celery command from the CLI.
$ export DJANGO_SETTINGS_MODULE="core.settings"  
$ celery -A core worker -l info -B

Executed Tasks, tasks_scripts DIR as defined in the EXEC Schedule

The output for each task can be found in the LOGS Directory.

Here is a LOG sample generated by a critical task that runs at every 5min:


CLI

Once the VENV is activated, we can use the console to interact with the codebase:

List available commands

$ python manage.py help 
(Truncated Output)
Type 'manage.py help <subcommand>' for help on a specific subcommand.
Available subcommands:
...
[cli]
    build_docs
    cmd_apps
    cmd_models
    cmd_showcfg
...

Generate DOCS

$ python manage.py build_docs

List Registered Apps

$ python manage.py cmd_apps
(Truncated Output)
 APP -> Webpack Loader
 APP -> Administration
 APP -> Authentication and Authorization
 ...

List Registered Models

$ python manage.py cmd_models
(Truncated Output)
 APP -> Administration
         |- (model) -> <class 'django.contrib.admin.models.LogEntry'>
 APP -> Authentication and Authorization
         |- (model) -> <class 'django.contrib.auth.models.Permission'>
         |- (model) -> <class 'django.contrib.auth.models.Group'>
         |- (model) -> <class 'django.contrib.auth.models.User'>

print Configuration

$ python manage.py cmd_showcfg
(Truncated Output)
 Cfg Key: INSTALLED_APPS -> ['webpack_loader', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'cli', 'apps.common', 'apps.pages', 'apps.users', 'apps.blog', 'debug_toolbar', 'allauth', 'allauth.account', 'allauth.socialaccount', 'allauth.socialaccount.providers.github', 'allauth.socialaccount.providers.google', 'django_quill']
 Cfg Key: DEBUG -> True
 Cfg Key: USE_TZ -> True
 Cfg Key: ROOT_URLCONF -> core.urls
 Cfg Key: MEDIA_ROOT -> D:\work\appseed-v2\media
 Cfg Key: APPEND_SLASH -> True
 Cfg Key: STATICFILES_FINDERS -> ['django.contrib.staticfiles.finders.FileSystemFinder', 'django.contrib.staticfiles.finders.AppDirectoriesFinder']
 Cfg Key: STATICFILES_DIRS -> D:\work\appseed-v2\static
 Cfg Key: STATIC_ROOT -> D:\work\appseed-v2\staticfiles  

Team

Core

Developers/Contractors


LICENSE

@EULA



Crafted and released under the AppSeed brand by Sm0ke

api-server-django's People

Contributors

app-generator avatar koladev32 avatar mominur-helios avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

api-server-django's Issues

Enabling /admin fails on authentication

User model (and auth) used in the backend seems to break the default django /admin,

How to reproduce:

1 enable /admin in core/urls.py:

from django.contrib import admin # <-- added 
from django.urls import include, path

urlpatterns = [
    path("api/users/", include(("api.routers", "api"), namespace="api")),
    path('admin/', admin.site.urls),  # <-- added
]

2 create super user:

$ python manage.py createsuperuser --email "[email protected]" --username "marx"
Password: 
Password (again): 
Superuser created successfully.

3 Frontend login works fine http://xyz:3000/authentication/sign-in

4 Backendlogin http://xyz:5000/admin fails with message:
Please enter the correct email and password for a staff account. Note that both fields may be case-sensitive.

No exception or errors are thrown in the backend console (even with DEBUG enabled).

Tests / Logout - Expected I/O

API URL : http://localhost:5000/api/users/logout

Request Headers

  • Content-Type: application/json
  • authorization: JWT_TOKEN_HERE

Request Body

{
    "token": "JWT_TOKEN_HERE"
}

Response For success

{
    "success": true,
    "msg": "Token revoked"
}

Response for unknown token

{
    "success": false,
    "msg": "User is not logged on"
}

Tests / Check Session - Expected I/O

API URL : http://localhost:5000/api/users/checkSession

Request Headers

  • Content-Type: application/json
  • authorization: JWT_TOKEN

Request Body - Empty

Response for success

{
    "success": true
}

Response for failure

{
    "success": false,
    "msg": "User is not logged on"
}

Docker - Error using the API in Docker

Set up - follow the README instructions

Get the code

$ git clone https://github.com/app-generator/api-server-django.git
$ cd api-server-django

Start the app in Docker

$ docker-compose up -d --build

The Build log ends without errors but the API is not available on port 5000

image

OAuth for Github - Feature migrated from NodeJS API

The goal of this task is to update this codebase in order to support OAuth for Github, in the same way as this NodeJS API:

image

For a complete set up:

  • Create a new GitHub OAuth app using https://localhost:3000 as the callback URL
  • Start the NodeJS API
    • port 5000 (default)
    • Save in .env the Github Secrets
  • Start the React UI

Go to the login page & use the GH Authentication.

All should work

For more information, I'm here.

Tests / Register - Expected I/O

API URL : http://localhost:5000/api/users/register

Request Headers

  • Content-Type: application/json

Request Body

{
    "username":"test",
    "password":"pass", 
    "email":"[email protected]"
}

Response for success

{
    "success": true,
    "userID": "1",
    "msg": "The user was succesfully registered"
}

Response for failure - email already taken

{
    "success": false,
    "msg": "Email already taken"
}

Tests / Login - Expected I/O

API URL : http://localhost:5000/api/users/login

Request Headers

  • Content-Type: application/json

Request Body

{
    "password":"pass", 
    "email":"[email protected]"
}

Response for success

{
    "success": true,
    "token": "JWT_TOKEN_HERE",
    "user": {
        "_id": "1",
        "username": "test",
        "email": "[email protected]"
    }
}

Response for failure - wrong password or email

{
    "success": false,
    "msg": "Wrong credentials"
}

Tests / Edit User - Expected I/O

API URL : http://localhost:5000/api/users/edit

Request Headers

  • Content-Type: application/json
  • authorization: JWT_TOKEN_HERE

Request Body

 {
        "userID": "1",
        "username": "test_updated",
        "email": "[email protected]"
}

Response For success

{
    "success": true
}

Response for error (token inactive, mismatch userId / token)

{
    "success": false,
    "msg": "Error updating user"
}

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.