P
P
Pavel Ivanov2015-04-24 13:52:23
Django
Pavel Ivanov, 2015-04-24 13:52:23

What can be used as help for a project in Django?

Good afternoon!
There is a task: take the directory structure:
directory/
./name.txt
./content.html
./subdirectory/
./subdirectory/name.txt
./subdirectory/content.html On the
left, display the names for each directory in the form of a tree, and on the right - content in content.html when clicked.
Before implementing help for the application in this form, I would like to ask: are there ready-made solutions that can be used and easily transferred from one server to another? (and what are the problems with help-s that store everything in relational databases?)
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Foo Bar, 2015-10-13
@atomheart

I’ll bring my bike)
First, the structure can be simplified and universalized at the same time:

docs/
./intro1.md
./intro2.md
./chapter1/
./chapter1/part1.md
./chapter1/part2.md

Those. file names are page names. The contents of this structure can be built simply as a tree of files of the specified directory.
Second, use the MarkDown syntax and extension under Python . Easy to edit and easily and correctly converted to html.
Thirdly, such a structure is handled very simply in Django:
urlpatterns = patterns(
    '',
    url(r'^wiki/(.*)$', 'wiki.views.wiki', name='wiki'),
)

def wiki(request, page=None):
    if not page:
        page = 'main'
    file_name = os.path.join('.', 'wiki', page)
    file_name = ''.join((file_name, '.md'))
    input_file = codecs.open(file_name, mode="r", encoding="utf-8")
    text = input_file.read()
    input_file.close()
    content = markdown.markdown(text)
    context = {
        "wiki_content": content,
        "wiki_title": page
    }
    return render_to_response(
        'wiki.html',
        dirs=get_dirs(),
        dictionary=context,
        context_instance=RequestContext(request)
    )

and the wiki.html template :
<!DOCTYPE html>
<html>
<head>
  <title>{{ wiki_title }} - Wiki</title>
</head>
<body>
  <h1>{{ wiki_title }}</h1>
  <hr>
  <div class="content">
    {{ wiki_content|safe }}
  </div>
</body>
</html>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question