Skip to content

Commit

Permalink
Improve parent app inspecting, fix template in example, improve Pytho…
Browse files Browse the repository at this point in the history
…n 2.7 compatible
  • Loading branch information
maxpoletaev committed Sep 30, 2016
1 parent 6b38df5 commit 20d0bc3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ __pycache__
dist
.idea
.venv
.cache
*.pyc
*.egg-info
*.sqlite3
13 changes: 7 additions & 6 deletions django_micro.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import absolute_import

import inspect
import os
import sys
Expand All @@ -20,11 +22,10 @@
_app_label = None


def _detect_app_module():
global _app_module
_app_module = sys.modules[inspect.stack()[2][0].f_locals['__name__']]
global _app_label
_app_label = os.path.basename(os.path.dirname(os.path.abspath(_app_module.__file__)))
def _setup_module():
app_module = sys.modules[inspect.stack()[2][0].f_locals['__name__']]
app_label = os.path.basename(os.path.dirname(os.path.abspath(app_module.__file__)))
globals().update(_app_module=app_module, _app_label=app_label)


def get_app_label():
Expand Down Expand Up @@ -69,7 +70,7 @@ def decorator(view_func):
# --------------------

def configure(config_dict={}):
_detect_app_module() # find in the stack module that calls this function
_setup_module() # find in the stack module that calls this function
config_dict.setdefault('TEMPLATE_DIRS', ['templates'])

kwargs = {
Expand Down
2 changes: 1 addition & 1 deletion example/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{% block title %}Example{% endblock %}

{% block body %}
<h1>{% say_hello name %}</h1>
<h1>{% say_hello "Django" %}</h1>

{% if posts %}
<table style="width: 100%">
Expand Down

0 comments on commit 20d0bc3

Please sign in to comment.