Пример #1
0
import djng

class RestView(object):
    def __call__(self, request, *args, **kwargs):
        method = request.method.upper()
        if hasattr(self, method):
            return getattr(self, method)(request, *args, **kwargs)
        return self.method_not_supported(request)
    
    @staticmethod
    def method_not_supported(request):
        return djng.Response('Method not supported')
    

class MyView(RestView):
    @staticmethod
    def GET(request):
        return djng.Response('This is a GET')
    
    @staticmethod
    def POST(request):
        return djng.Response('This is a POST')

if __name__ == '__main__':
    djng.serve(MyView(), '0.0.0.0', 8888)
Пример #2
0
import djng, os, datetime

djng.template.configure(
    os.path.join(os.path.dirname(__file__), 'example_templates'))


def index(request):
    return djng.TemplateResponse(request, 'example.html', {
        'time': str(datetime.datetime.now()),
    })


if __name__ == '__main__':
    djng.serve(index, '0.0.0.0', 8888)
Пример #3
0
class DemoForm(djng.forms.Form):
    name = djng.forms.CharField(max_length = 100)
    email = djng.forms.EmailField()
    optional_text = djng.forms.CharField(required = False)

def validate(request):
    if request.method == 'POST':
        form = DemoForm(request.POST)
        if form.is_valid():
            return djng.Response('Form was valid: %s' % djng.escape(
                repr(form.cleaned_data)
            ))
    else:
        form = DemoForm()
    return djng.Response("""
    <form action="/validate/" method="post">
    %s
    <p><input type="submit">
    </form>
    """ % form.as_p())

app = djng.Router(
    (r'^$', index),
    (r'^search/$', search),
    (r'^submit/$', submit),
    (r'^validate/$', validate),
)

if __name__ == '__main__':
    djng.serve(app, '0.0.0.0', 8888)
Пример #4
0
import djng

def hello(request):
    return djng.Response('Hello, world ' * 100)

def goodbye(request):
    return djng.Response('Goodbye, world ' * 100)

app = djng.Router(
    (r'^hello$', hello),
    (r'^goodbye$', djng.middleware.GZip(goodbye)),
)

if __name__ == '__main__':
    djng.serve(app, '0.0.0.0', 8888)
Пример #5
0
import settings


def bounce(request, hash, url):
    """Redirect to ``url``, but only if it matches the ``hash``."""
    print url
    expected = hashlib.sha1(settings.secret + url)
    if expected.hexdigest() == hash:
        return http.HttpResponseRedirect(url)
    else:
        return djng.Response('redirecting to /dev/null')


def home(request):
    url = 'http://github.com/jbalogh/moonshoes'
    return djng.Response('This is <a href="%s">moonshoes</a>' % url)



# Give the bouncer a v1 namespace so it can expand later.
app = djng.ErrorWrapper(djng.Router(
    ('^$', home),
    (r'^v1/([^/]+)/(.*)$', bounce),
))


if __name__ == '__main__':
    assert hasattr(settings, 'secret'), "Put a secret key in settings.py"
    djng.serve(app, '0.0.0.0', 8000)
Пример #6
0
    <form action="/validate/" method="post">
    %s
    <p><input type="submit">
    </form>
    """ % form.as_p())


app = djng.Router(
    (r'^$', index),
    (r'^search/$', search),
    (r'^submit/$', submit),
    (r'^validate/$', validate),
)

if __name__ == '__main__':
    djng.serve(app, '0.0.0.0', 8888)

########NEW FILE########
__FILENAME__ = example_hello
import djng


def index(request):
    return djng.Response('Hello, world')


if __name__ == '__main__':
    djng.serve(index, '0.0.0.0', 8888)

########NEW FILE########
__FILENAME__ = example_middleware
Пример #7
0
import djng, os, datetime

djng.template.configure(
    os.path.join(os.path.dirname(__file__), 'example_templates')
)

def index(request):
    return djng.TemplateResponse(request, 'example.html', {
        'time': str(datetime.datetime.now()),
    })

if __name__ == '__main__':
    djng.serve(index, '0.0.0.0', 8888)
Пример #8
0
    return djng.Response("""
    <form action="/validate/" method="post">
    %s
    <p><input type="submit">
    </form>
    """ % form.as_p())

app = djng.Router(
    (r'^$', index),
    (r'^search/$', search),
    (r'^submit/$', submit),
    (r'^validate/$', validate),
)

if __name__ == '__main__':
    djng.serve(app, '0.0.0.0', 8888)

########NEW FILE########
__FILENAME__ = example_hello
import djng

def index(request):
    return djng.Response('Hello, world')

if __name__ == '__main__':
    djng.serve(index, '0.0.0.0', 8888)

########NEW FILE########
__FILENAME__ = example_middleware
import djng