Giter Club home page Giter Club logo

django-redis-views's Introduction

django-redis-views

image

image

Simple Redis-based generic views for serving your Django-backed Ember CLI apps.

Documentation

The full documentation is at https://django-redis-views.readthedocs.org.

Features

Background

Ember CLI and other single-page javascript apps can be challenging to deploy.

Luke Melia presented a talk called Lightning Fast Deployment of Your Rails-backed JavaScript app, which eventually led to the creation of ember-cli-deploy.

This project acts as the glue between ember-cli-deploy and Django by providing generic views to serve Redis-backed index pages for single page javascript applications.

Quickstart

Let's assume we already have an Ember CLI app that we're ready to deploy. We're using the ember-deploy-redis adapter and we ran ember deploy to push the index.html file into Redis. In this case, we'll pretend that the Ember CLI project's name is ember-cli-my-great-app.

First, install django-redis-views:

pip install django-redis-views

In your Django settings file, set the Redis url. For example, you may want to access Redis on the localhost running on the default port. In which case, you would add something like this to the your settings.py file:

REDIS_URL = 'redis://localhost:6379/0'

Then, to use it in your Django project, first add a new view to a views.py file:

from redis_views import RedisView


class EmberAppIndex(RedisView):
    app_name = 'ember-cli-my-great-app'

And then set it a route for it in your urls.py file:

from django.conf.urls import url
from myapp.views import EmberAppIndex


urlpatterns = [
    url(r'^$', EmberAppIndex.as_view()),
]

At this point, you should be able to go to your root url and see your index page!

TODO: Walk through a full example project.

Injecting Context to your Template

If you want to use Django's template engine to replace values in your Ember index file, you can do that by injecting the context. Let's pretend that we have this very simple Ember index page:

<p>Hello {{ name }}!</p>

In order to inject {{ name }} from Django into the Ember index page, you'll want to add to the context. This package is built upon the generic views in Django, so we inject context the same way that they do. In your views.py file (using the same conventions as above):

from redis_views import RedisView

class EmberAppIndex(RedisView):

    . . . 

    def get_context_data(self, **kwargs):
        # Call the base implementation first to get a context
        context = super(EmberAppIndex, self).get_context_data(**kwargs)
        # Add in the name value (you could also use a dynamic value from a database object)
        context['name'] = 'Joe'
        return context

Then, in the template, it will fill in the value with your supplied value. As mentioned in the comment, you can inject pretty much anything that could normally be handled by Django templates, such as a CSRF token.

Running the Tests

To run the tests, please do the following in your terminal:

# Install the testing requirements
pip install -r requirements-test.txt

# Run the tests
py.test

Cookiecutter Tools Used in Making This Package

  • cookiecutter
  • cookiecutter-djangopackage

django-redis-views's People

Contributors

a7madnassar avatar kevinlondon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

django-redis-views's Issues

How did you deploy Ember static files into Django project?

Thanks for putting this project together! I am able to deploy the Ember index file to my local Redis server and serve it via Django, but I'm not sure the best way to deploy the static files. Are you deploying the static files to S3 or into your Django project directly? Any tips you can provide would be appreciated. Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.