Skip to content
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
Cannot retrieve contributors at this time
from pyramid.config import Configurator
from pyramid.view import view_config
from wsgiref.simple_server import make_server
from pyramid_mongoengine import MongoEngine
db = MongoEngine()
class User(db.Document):
"""Simple user model"""
email = db.StringField()
username = db.StringField()
@view_config(route_name="hello", renderer="json")
def hello(request):
return {"msg": "Hello Pyramid MongoEngine"}
@view_config(route_name="add", request_method="POST", renderer="json")
def new_user(request):
params = dict(request.params)
user = User(**params)
return {"new_user": user}
@view_config(route_name="show", renderer="json")
def show(request):
username = request.matchdict["username"]
user = User.objects.get_or_404(username=username)
return {"user": user}
if __name__ == "__main__":
config = Configurator()
config.add_settings({"mongodb_name": "pyramid_mongoengine_test"})
config.add_route("hello", "/")
config.add_route("add", "/new/")
config.add_route("show", "/{username}/")
app = config.make_wsgi_app()
server = make_server('', 8080, app)