-
Notifications
You must be signed in to change notification settings - Fork 3
Creating snippets
First of all, you'll need to [configure your DJSTRUCT_HOME](Environment Variables) environment variable to do this.
Then create a "snippets" directory inside it. That's where will live your snippets:
mkdir $DJSTRUCT_HOME/snippets
Now Django-Structurer will search this folder for your snippets.
It's very simple, lets suppose that you want a snippet that has some import that you use in almost all your views. Ex:
from django.shortcuts import redirect
from django.http import HttpResponseRedirect
from django.shortcuts import get_object_or_404
Just create a file with this content and give it a name that represents it nicely, like "useful_imports.snippets"
Notice that the termination MUST BE snippets to be considered as a snippet for Django-Structurer.
Now that you've made your snippet, you'll probably want to use it. So if you want that useful imports in your views by default, you need to tell your custom project structure that in your view.py file you'll be using that snippet:
- name: view.py
snippets: [useful_imports]
Simple as that!
If you'll want to keep yourself organized, you can organize your snippets in different folders, ex:
|.myStructs
|----snippets
|----apps
|----views
|----useful_imports.snippets
|----models
|----useful_imports.snippets
|----whatever.snippets
So you can use them in your project struct file like:
snippets: [apps.views.useful_imports, apps.models.useful_imports, whatever]