contributor wanted : feel free to contact me at aniketsarkar@yahoo.com
Navycut is a high-level Python Web framework that encourages rapid development and clean, pragmatic design. Thanks for checking it out.
It's actually a Full Stack web framework using Flask(werkzeug) as backend wsgi server and try to deliver the service and api like Django.
The official documentation is online at navycut.github.io.
Use the package manager pip to install navycut.
python3 -m pip install navycut
Install from source code
git clone https://github.com/flaskAio/navycut.git && cd navycut/
python3 setup.py install
navycut --version
0.0.5
Navycut promises to deliver the fullstack service using the following features:
- Customished ORM using SQLAlchemy.
- It's comes with all the sqlalchemy features with some extra features.
- It's have the own Image, Json, Text, Integer, String and many other fields like Django ORM has.
- Some fileds have the default choices system to add value by providing a tuple data like Django ORM.
- Inbuild Admin system using flask-admin. So all the flask-admin features are applicable here.
- Inbuild authentication stystem using flask-login.
- Form system using wt-forms.
- SMTP mail integration using flask-mail.
- Flask-migrate to migrate the database.
- Custom app features like django.
- ExpressJs like view functions to provide more interactive service.
navycut --help
or
navycut [COMMAND] --help
navycut createproject blog
This command will create a project directory containing the basic files created by navycut at the specified location.
The directory structure will be:
blog
├── blog
│  ├── asgi.py
│  ├── settings.py
│  ├── test.py
│  └── wsgi.py
├── templates
│  └── README.md
├── manage.py
python manage.py runserver
or
python manage.py runserver 0.0.0.0:8000 # to start a server on different port
This command will start the development server on localhost:8888 or the provided address. Now you should create an app to start writing the urls and appropriate views function.
python manage.py createapp blogapp
This command will create an app directory containg some navycut specified file at the project directory location.
The app folder structure will be:
blogapp
├── admin.py
├── __init__.py
├── models.py
├── sister.py
├── urls.py
└── views.py
Now the Project folder structure will be:
blog
├── blog
│  ├── asgi.py
│  ├── settings.py
│  ├── test.py
│  └── wsgi.py
├── blogapp
│  ├── admin.py
│  ├── __init__.py
│  ├── models.py
│  ├── sister.py
│  ├── urls.py
│  └── views.py
├── templates
| └── README.md
├── manage.py
now you need to register the newly created app with the project.
To do this you must perform the following steps.
- open the directory containing the same name with project.
- open settings.py file.
- Now findout the block called
INSTALLED_APPS
. - Under this
INSTALLED_APPS
list add your app. - Suppose your app name is
blogapp
then add the following line underINSTALLED_APPS
: "blogapp.sister.BlogappSister".
Your settings.py file should look like this:
INSTALLED_APPS = [
"navycut.orm.sqla",
"navycut.contrib.cors",
"navycut.contrib.auth",
"navycut.contrib.mail",
"navycut.contrib.admin",
"navycut.helpers.upload_server",
"blogapp"
]
- to know more about the available commands:
navycut --help
- to create a project directory at the present location:
navycut createproject project_name
- to create a app inside the project directory:
cd project_name
python manage.py createapp app_name
- to migrate the database:
python manage.py migrate
- to apply the migration to the database:
python manage.py makemigrations
- to create the superuser to access the admin:
python manage.py createsuperuser
- to start the interactive development server
python manage.py runserver
from navycut.orm import sql
from datetime import datetime
class Blog(sql.Model):
id = sql.fields.Integer(pk=True)
title = sql.fields.Char(max_length=50)
body = sql.fields.Text(required=True)
image = sql.fields.Image(required=True)
created_at = sql.fields.DateTime(default=datetime.now)
author_ptr_id = sql.fields.ForeignKey("Author")
class Author(sql.Model):
id = sql.fields.Integer(pk=True)
name = sql.fields.Char(max_length=100, required=True)
image = sql.fields.Image(required=True)
blog = sql.fields.OneToMany("Blog")
# urls.py
from navycut.urls import path, url, include
from . import views
"""
The default url_prefix is the app name i.e "/blog" for this case.
If you want to change it and use your own customized name then
plese update the url_prefix for a particular app on the sister.py file
under the AppSister class.
"""
urlpatterns = [
path('/', views.BlogView, name='blog-index'),
url('/<int:id>', views.blog_detail, name='blog-detail'),
url('/search/?id=1', views.blog_search, name='blog-search'),
include('/polls', 'polls.urls') # include urlpatterns from another app
]
# views.py
from navycut.urls import MethodView
from .models import Blog
"""
Here you can use views method like expressJs.
Just simply pass the request and response object as
arguments of the view function.
"""
class BlogView(MethodView):
def get(self):
blogs = Blog.query.all()
return self.render('blog/blog_listing.html', {'blogs': blogs})
def blog_details(req, res, id):
blog = Blog.query.get(id)
return res.json(blog)
def blog_search(req, res):
id = int(req.args.get('id'))
blog = Blog.query.get(id)
return res.json(blog)
<html>
<head>
<title>Blog Listing</title>
</head>
<body>
<h1>All Blogs</h1>
<ul>
{% for blog in blogs %}
<li>
<h2>{{ blog.name }}</h2>
<img src="{{blog.image}}">
</li>
{% endfor %}
</ul>
</body>
from navycut.contrib import forms
class RegistrationForm(forms.Form):
username = forms.StringField('Username', [forms.validators.Length(min=4, max=25)])
email = forms.StringField('Email Address', [forms.validators.Length(min=6, max=35)])
password = forms.PasswordField('New Password', [
forms.validators.DataRequired(),
forms.validators.EqualTo('confirm', message='Passwords must match')
])
confirm = forms.PasswordField('Repeat Password')
accept_tos = forms.BooleanField('I accept the TOS', [forms.validators.DataRequired()])
from navycut.auth import login_required, current_user, group_required
from navycut.http import JsonResponse
from navycut.urls import MethodView
class AuthView(MethodView):
@login_required
def get(self):
return JsonResponse(logged_in_username=current_user.username)
@login_required
@group_required('super_admin')
def get_data(req, res):
return res.json(username=req.user.username) # current_user == req.user
from navycut.admin import admin
from navycut.admin.site.views import NCAdminModelView
from .models import Blog, Author
class AuthorAdminModelView(NCAdminModelView):
"""Customize the look of the auto-generated admin for the Member model"""
excluded_fields = ['name',]
admin.register_model(Blog) # Use the default options
admin.register_model(Author, AuthorAdminModelView) # Use the customized options
my vpa id: aniketsarkar@ybl
- Fork and clone this repository
- Make some changes as required
- Write unit test to showcase its functionality
- Submit a pull request under
main
branch
- Fork and clone this repository
- Create a virtual environment using python virtualenv module on the project root directory.
- Activate the virtual environment and install the package dependencies mentioned on
requirements.txt
file. - Now run this command :
python setup.py install
. This command will installnavycut
on the virtual environment. - Make any changes on your local code.
- Run again the command :
python setup.py install
. - Now create a separate project inside the example folder and start testing for your code changes.
- If you face any difficulties to perform the above steps, then plese contact me at:
aniketsarkar@yahoo.com
.
GNU General Public License v3 or later (GPLv3+)
Copyright (c) 2021 navycut(aniketsarkar@yahoo.com)