Skip to content
arruda edited this page Nov 21, 2011 · 4 revisions

Criating Custom Snippets

First of all, you'll need to [configure your DJSTRUCT_HOME](Environment Variables) environment variable to do this.

Create A Snippets Directory

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.

Create 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.

Using The Snippet

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!

Organizing Your Snippets

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]

Clone this wiki locally