简体   繁体   English

Django:存储自己编写的脚本的位置

[英]Django: Where to store own written scripts

I have recently started with the Django framework.我最近开始使用 Django 框架。

I have some custom python scripts (could also later be custom packages) that I want to use.我有一些我想使用的自定义 python 脚本(以后也可能是自定义包)。 Where to I store them?我在哪里存放它们? (I want to import them in certain django.py files) (我想在某些 django.py 文件中导入它们)

I know in the framework you can have templates, static and media folders to keep various files.我知道在框架中你可以有模板、static 和媒体文件夹来保存各种文件。 Would your own custom scripts sit in here or do you keep them somewhere else?您自己的自定义脚本会放在这里还是将它们保存在其他地方? (like in static where your css and js files sit) (例如在 static 中,您的 css 和 js 文件所在的位置)

Can I just create a folder in the project called modules/py_scripts or is there a specific standard?我可以在项目中创建一个名为 modules/py_scripts 的文件夹还是有特定的标准?

Thanks in advance!提前致谢!

That's part of your application design .这是您的应用程序设计的一部分。 If you feel that you've got some module which you might be actually using in another project (but for now it's only the one you are working on), I'd create a directory within your project, let's say "common", with its own __ init__.py and your possibly re-usable module.如果你觉得你有一些你可能在另一个项目中实际使用的模块(但现在它只是你正在处理的那个),我会在你的项目中创建一个目录,让我们说“common”,它自己的 __ init__.py 和您可能可重用的模块。

The thing is, nobody will tell you how to actually structure your project, as we have limited knowledge of what it's supposed to do and how you are planning to realize it.问题是,没有人会告诉你如何实际构建你的项目,因为我们对它应该做什么以及你打算如何实现它的了解有限。 As I said previously, deciding on how to logically structure an application (how to structure folders, what models to include etc.) is part of the design which is rather complex and creative task.正如我之前所说,决定如何合理地构建应用程序(如何构建文件夹、要包含哪些模型等)是设计的一部分,这是一项相当复杂和创造性的任务。 Beside that, in some cases your application design (its directories structure) might be framework-agnostic.除此之外,在某些情况下,您的应用程序设计(其目录结构)可能与框架无关。

Having said that, I suggest you to take a look on how some popular websites/applications built on top of django have been implemented: https://vsupalov.com/six-big-open-source-django-codebases/话虽如此,我建议您看看一些基于 django 的流行网站/应用程序是如何实现的: https://vsupalov.com/six-big-open-source-django-codebases/

This one looks quite good: https://github.com/edx/edx-platform/tree/master/cms这个看起来还不错: https://github.com/edx/edx-platform/tree/master/cms

Please pay attention to how each of the applications from cms/djangoapps is structured.请注意 cms/djangoapps 中的每个应用程序的结构。

In your app,you can create files like custom.py and save it,and later can call like this-在您的应用程序中,您可以创建 custom.py 之类的文件并将其保存,以后可以像这样调用-

from .custom import func()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM