Reputation: 31
I have recently started with the Django framework.
I have some custom python scripts (could also later be custom packages) that I want to use. Where to I store them? (I want to import them in certain django .py files)
I know in the framework you can have templates, static and media folders to keep various files. 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)
Can I just create a folder in the project called modules/py_scripts or is there a specific standard?
Thanks in advance!
Upvotes: 2
Views: 1795
Reputation: 3076
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.
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/
This one looks quite good: https://github.com/edx/edx-platform/tree/master/cms
Please pay attention to how each of the applications from cms/djangoapps is structured.
Upvotes: 3
Reputation: 1125
In your app,you can create files like custom.py and save it,and later can call like this-
from .custom import func()
Upvotes: 0