question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Class based views

See original GitHub issue

How to create class based views? Like this

from pyramid.view import (
    view_config,
    view_defaults
    )

@view_defaults(renderer='home.pt')
class TutorialViews:
    def __init__(self, request):
        self.request = request

    @view_config(route_name='home')
    def home(self):
        return {'name': 'Home View'}

    @view_config(route_name='hello')
    def hello(self):
        return {'name': 'Hello View'}

More info: https://docs.pylonsproject.org/projects/pyramid/en/latest/quick_tutorial/view_classes.html

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

6reactions
dmontagucommented, Nov 2, 2019

Here’s an approach I use to organize endpoints into classes (mostly so I don’t have to repeat all the dependencies in each signature): https://gist.github.com/dmontagu/87e9d3d7795b14b63388d4b16054f0ff

2reactions
monkutcommented, Nov 2, 2019

It can be nice to group resources (user) by class for readability.

Something like: https://flask-restful.readthedocs.io/en/latest/quickstart.html#a-minimal-api

Read more comments on GitHub >

github_iconTop Results From Across the Web

Class-based views
A view is a callable which takes a request and returns a response. This can be more than just a function, and Django...
Read more >
Django Class-Based-View Inspector -- Classy CBV
Django's class-based generic views provide abstract classes implementing common web development tasks. These are very powerful, and heavily-utilise Python's ...
Read more >
Class based views - Advanced Django Training
Django's class-based views provide a object-oriented (OO) way of organizing your view code. Most Django tutorials and training material start developers off ...
Read more >
Django : Class Based Views vs Function Based Views
Class-based views provide an alternative way to implement views as Python objects instead of functions. They do not replace function-based views, ...
Read more >
DetailView - Class Based Views Django
Class based views are simpler and efficient to manage than function-based views. A function based view with tons of lines of code can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found