DjangularServe提供对Django和Angular PWA的完全控制和管理。

djangular-serve的Python项目详细描述


PyPIContributorsForksStargazersIssuesMIT LicenseLinkedIn

目录

关于项目

Product Name Screen Shot

使用

构建

入门

要开始使用Djangular Serve,请继续执行以下说明。。。在

先决条件

这是一个如何列出使用软件所需的内容以及如何安装的示例。在

  • npm和角度
See https://nodejs.org for installing NODEJS/NPM on your machine correctly

安装后运行:

^{pr2}$

安装

1。安装djangular serve

pip install djangular-serve or pip3 install djangular-serve

2。添加到Django安装的应用程序

'djangular_serve'

3。添加URL

urlpatterns=[
    ...
    path('', include('djangular_serve.urls'),
    or
    url(r'^', include('djangular_serve.urls'),
]

4。在你的设置.py文件添加和编辑以下设置:

设置相关路径以允许djangular serve查找模板和静态文件

这是一种方法。不管你用什么方法去做。

在项目内部建立如下路径:APP_DIR/“subdir”。

BASE_DIR= Path(__file__).resolve(strict=True).parent.parent  # Absolute root pathAPP_DIR= Path(__file__).resolve(strict=True).parent  # 'example' projectURL= os.path.relpath(APP_DIR / "static")# example/staticANGULAR_DIR= os.path.join(BASE_DIR / ".")# root/ngservetest <- Your Angular project

告诉Django查找静态文件和模板。

在调试中,如果愿意,可以为本地dev使用不同的静态位置。

再次将此设置为最适合您的项目的方式。

if DEBUG:
    DJANGO_TEMPLATE_DIRS=(
        os.path.join(APP_DIR, 'templates'),
    )STATICFILES_DIRS=(
        os.path.join(APP_DIR, 'static_files'),
    )else:  # Change later for production if needed.DJANGO_TEMPLATE_DIRS=(
        os.path.join(APP_DIR, 'templates'),
    )STATICFILES_DIRS=(
        os.path.join(APP_DIR, 'static_files'),
    )TEMPLATES=[{'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': DJANGO_TEMPLATE_DIRS,
        ...
        ...
    },
]

命令

# Build Angular application to Django static
serve -s ng

# Move relevant static files to respective directories
serve -mv js, css, img or all

# Make a new directory in your static root
serve -mk <any-dir>

PWA使用

下面的设置将自动将应用程序分发到您选择的路径

""" Serve CDN or static css files to your template. """STYLESHEETS=[{'src': 'example/static/ng_css/styles.css'},
    # OR#    {#        'src': '{}/styles.css'.format(URL)#    },]""" Serve CDN or static js files to your template. """JAVASCRIPT=[{'src': 'example/static/ng_js/main.js'},
    {'src': 'example/static/ng_js/polyfills.js'},
    {'src': 'example/static/ng_js/runtime.js'},
]""" Serve CDN or static fonts files to your template. """FONTS=[{'src': 'https://fonts.googleapis.com/icon?family=Material+Icons'},
]# Path to get service-workerSERVICE_WORKER_PATH= os.path.join(BASE_DIR, 'example/templates', 'sw.js')# Gets name of service worker to automatically register .e.g 'sw.js'# This will tell manifest and url to get this specific file and serve.SERVICE_WORKER_NAME= os.path.basename(SERVICE_WORKER_PATH)APP_NAME='Djangular Serve'APP_DESCRIPTION="Build Angular into Django static"APP_THEME_COLOR='#000000'APP_BACKGROUND_COLOR='#ffffff'APP_DISPLAY='standalone'APP_SCOPE='/'APP_ORIENTATION='any'APP_START_URL='/'APP_STATUS_BAR_COLOR='default'APP_DIR='.'APP_LANG= LANGUAGE_CODE
APP_ICONS=[{'src': '/static/images/logo_icons.png',
        'sizes': '160x160'}]APP_ICONS_APPLE=[{'src': '/static/images/apple_icons.png',
        'sizes': '160x160'}]APP_SPLASH_SCREEN=[{'src': '/static/images/icons/splash-640x1136.png',
        'media': '(device-width: 320px) and (device-height: 568px) and (-webkit-device-pixel-ratio: 2)'}]

下面是一个设置_index.html模板的示例。

<!doctype html>
{% load static %}
{% load serve_tags %}
{% load i18n %}
{% get_current_language as LANGUAGE_CODE %}
{% get_current_language_bidi as LANGUAGE_BIDI %}
<html lang="{{ LANGUAGE_CODE|default:'en' }}" {% if LANGUAGE_BIDI %}dir="rtl"{% endif %}>
<head>
  <meta charset="utf-8">
  <title>{% block title %}{% endblock title %}</title>
  <base href="/">

  {% block head %}{% manifest_meta %}{% endblock head %}
  <!-- [if lt IE 9]>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.min.js"
          type="text/javascript"></script>
  <![endif] -->

  {% serve_fonts %}
  {% serve_css %}
</head>

<body class="mat-typography">
{% block body %}


<app-root>{% block content%}{% endblock content %}</app-root>


  <!-- JS -->
  {% serve_js %}
  {% block js %}{% endblock js %}

<!-- [if lte IE 9]>
<script src="https://cdnjs.cloudflare.com/ajax/libs/placeholders/3.0.2/placeholders.min.js"></script>
<![endif] -->
{% endblock body %}
</body>
</html>

有关更多示例,请参阅 Documentation

路线图

open issues 以获取建议功能(和已知问题)的列表。在

贡献

您所做的任何贡献都将受到的高度赞赏。在

  1. 把项目分成两半
  2. 提交更改
  3. 推到树枝上
  4. 打开拉取请求

许可证

根据麻省理工学院的许可证分发。有关更多信息,请参阅djangular\u serve/docs中的LICENSE。在

联系人

LinkedIn:https://linkedin.com/in/jonnydoyle 项目链接:https://github.com/forafekt/djangular-serve

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java广播接收器未检测到按键事件   java不为特定列更改创建修订   java采用了更实用的方法   java桌面窗格HTML呈现   java处理internet连接丢失   java在调整JFrame的大小时,如何防止JTable的列调整大小?   如何用Java中的“Scanner.hasNext”完成程序   具有模块名称的java停止IntelliJ项目工具窗口?   执行已编译的Rails-Warbler JAR文件时发生java加载错误   java Spring数据redis存储库不支持集合查询?   每个客户端的java队列请求   获取Java中的JSON嵌套数组元素   java GWT,Vaadin ConcurrentModificationException   firebase存储中的java在保存照片之前,我需要发送两次照片   JavaSpringEleaf如何在容器外使用变量