Skip to main content

Django's database stored web content processor

Project description

deep-pages

Django's database stored web content processor

About

My motivation to create this small package raises when I was needing to create some small pages with static URL and want to use some template tags. So, unfortunatelly Django's Flat Pages wasn't enough in my case.

Ok, so what the DeepPages does? With DeepPages you can store a page (or any other text-based content) into your database using the Page Model, set a static URL to that and get it rendered. Simple.

How it works?

DeepPages provides two ways to being used into your Django's project:

1. As Middleware

All you need is add DeepPageTemplateRendererMiddleware as a middleware in your settings. I really do recommend to insert this middleware in the end of MIDDLEWARE's list.

As Middleware

2. As PageView (TemplateView's inheritance)

Actually it was the first way that I've created. You need to include DeepPage's url patterns into your project (see Install).

As Middleware

Signals

DeepPages has three signals that you can connect to workaround. You can import those from signals.py.

They are: page_requested, page_found and page_not_found.

from django.dispatch import receiver
from deeppages.signals import page_requested, page_found, page_not_found

@receiver(page_requested)
def page_requested_callback(sender, path, request):
    # do something here
    pass


@receiver(page_not_found)
def page_not_found_callback(sender, path, request):
    # do something here
    pass


@receiver(page_found)
def page_found_callback(sender, path, request, page, content, context):
    # do something here

In page_found signal's receiver you can change the arguments content and context to get rendered by Middleware or PageView (depending how you've configured in your project).

Programmatically DeepPages Rendering

You can get a DeepPage rendered programmatically. To do this you just need to import get_page_by_name function from utils.py.

Function statement:

def get_page_by_name(name, context=None, callback=None)

Where:

  • name = Page name
  • context (optional) = A dictionary with context for template processing
  • callback (optional) = A function to be called with arguments page and context before rendering and should return the new page content.

So, assuming that you've created a page named as test-page, do it:

from deeppages.utils import get_page_by_name

def render():
    rendered_page = get_page_by_name('test-page', ctx)
    # do something

Install

pip install deeppages

After package install, add deeppages in your INSTALLED_APPS list.

INSTALLED_APPS = [
    ...
    'deeppages.apps.DeepPagesConfig',
    ...
]

If you want to use the Middleware way (personally, it's my preferred btw), open your settings file and look for MIDDLEWARE list.

MIDDLEWARE = [
   ...
   'deeppages.middleware.DeepPageTemplateRendererMiddleware',
]

Or, if you want to use the PageView way, you just need to open your project's URL patterns file (urls.py) and configure DeepPage as an URL Pattern:

from deeppages.views import PageView


urlpatterns = [
    ...
    url(r'^deeppages/', include(deeppages.urls, namespace='deeppages')),
    ...
]

This way, you can create a page with URL /test-page/ and it will be found at: /deeppages/test-page/.

Of course that you can use as default URL seeker, maybe for small projects it can work fine. For example:

urlpatterns = [
    ...
    url(r'', include(deeppages.urls, namespace='deeppages')),
    ...
]

Or, if you want to make your own View, you can import the PageView class and inherite from that:

from deeppages.view import PageView

class YourNewView(PageView):
    # do something

And your /test-page/ will be found at /test-page/ as well.

I'm using this package in a project that I'm developing and isn't under production environment. So, be careful to use this in production.

Feel free to make it better and send your updates/suggestions.

Enjoy.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

deeppages-0.2.4.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

deeppages-0.2.4-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

File details

Details for the file deeppages-0.2.4.tar.gz.

File metadata

  • Download URL: deeppages-0.2.4.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.31.1 CPython/3.6.3

File hashes

Hashes for deeppages-0.2.4.tar.gz
Algorithm Hash digest
SHA256 00b582a2d81dbd1d7c2e15bed20fe7f904b371e6974214bd7f6423bb6c87a925
MD5 f5e20edf8794a875c18be7042bca95e2
BLAKE2b-256 fe57e6fd6aefb1a4c9690e5b65aaa8b92ab3fa81ed9b5804a3d096d2a257b1ee

See more details on using hashes here.

File details

Details for the file deeppages-0.2.4-py3-none-any.whl.

File metadata

  • Download URL: deeppages-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 14.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.31.1 CPython/3.6.3

File hashes

Hashes for deeppages-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 9f1e58202a3f92981323931e54ca905d315f996f70090ef99ebe0b59c193f5c0
MD5 6800eaf5b3773bde94b63bb803691780
BLAKE2b-256 cb5db01deda680f6d37ea37d5e19a410571a6fee1e8a1a361d447a31d676060c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page