Django Export XLS 【Windows安装】

今天在windows电脑上安装django-export-xls的时候报错了:

(venv) PS F:\Pycharm_Projects\Ruoyi-Energy> pip3 install django-export-xls                                                         
Collecting django-export-xls
  Using cached django-export-xls-0.1.1.tar.gz (3.2 kB)
  Preparing metadata (setup.py) ... error
  ERROR: Command errored out with exit status 1:
obaby\AppData\Local\Temp\pip-pip-egg-info-u0lvqod1'
       cwd: C:\Users\obaby\AppData\Local\Temp\pip-install-xrhra6sx\django-export-xls_d72b66d322264c26b516fda785f307fd\
  Complete output (5 lines):
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "C:\Users\obaby\AppData\Local\Temp\pip-install-xrhra6sx\django-export-xls_d72b66d322264c26b516fda785f307fd\setup.py", line 4, in <module>
      README = open(os.path.join(os.path.dirname(__file__), 'README.rst')).read()
  UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 918: illegal multibyte sequence
  ----------------------------------------

Continue Reading

Django Export XLS

python读写csv是非常方便的,但是读写xls就稍微麻烦一些,涉及到行和列的问题。为了导出数据,搜了一下找到这么个插件:https://github.com/Daiech/django-export-xls,集成非常简单,只需要下面几步就ok了:

1. 安装::
      $ pip install django-export-xls
2. 将"export_xls" 添加到 INSTALLED_APPS::
      INSTALLED_APPS = (
          ...
          'export_xls',
      )
3. 修改以下两个路径MEDIA_ROOT 和MEDIA_URL eg::
      import os
      MEDIA_ROOT = os.sep.join([os.path.dirname(os.path.dirname(__file__)), 'media'])
      MEDIA_URL = '/media/'
4. 执行数据导出:
   定义以下几个数据:文件名、表头、导出数据

Continue Reading

mosquitto not authorised

Eclipse Mosquitto is an open source (EPL/EDL licensed) message broker that implements the MQTT protocol versions 5.0, 3.1.1 and 3.1. Mosquitto is lightweight and is suitable for use on all devices from low power single board computers to full servers.
The MQTT protocol provides a lightweight method of carrying out messaging using a publish/subscribe model. This makes it suitable for Internet of Things messaging such as with low power sensors or mobile devices such as phones, embedded computers or microcontrollers.
The Mosquitto project also provides a C library for implementing MQTT clients, and the very popular mosquitto_pub and mosquitto_sub command line MQTT clients.

最近需要用mqtt来实现消息处理,在windows上安装Mosquitto之后,不使用用户名密码提示connection refused: not authorised。结果添加用户名密码之后还是提示同样的错误。

Continue Reading

Django 代码保护

常用的代码保护不外乎下面几种方法:

发行 .pyc 文件
代码混淆
使用 py2exe
使用 Cython

django发布的需要以服务运行,通过其他的几种方法来实现保护,都不太现实。所以发布可以通过cython的方式实现。

1. 安装cython

pip3 install cython

2.在项目目录创建setup.py 编辑内容如下,其中“app/file1.py”是你所要打包的py文件名,这儿需要把app下所有的py文件都添加进来(当然也可以添加部分)

from distutils.core import setup

from Cython.Build import cythonize

fileSet = set()

fileSet.add("UserBase/models.py")
fileSet.add("UserBase/views.py")

setup(

    ext_modules=cythonize(fileSet)

)

Continue Reading