Hello world of sprox with pyramid - part 2 - python

I've tried to build the simplest possible form in Sprox using pyramid.
# model.py
class Allocation:
# some fields ...
class SproxForm(AddRecordForm):
__model__ = Allocation
sprox_form = SproxForm(DBSession)
# views.py
#view_config(route_name='sprox_add', renderer='templates/sprox.pt')
def sprox_form_add(request):
return {'form':sprox_form,'form_input':{}}
<!-- sprox.pt -->
<html>
<body>
<div tal:content="structure form(form_input)"/>
</body>
</html>
When I navigate to that view in the browser, I get
Traceback (most recent call last):
File "D:\prg\py2\lib\site-packages\pyramid_debugtoolbar-1.0.4-py2.7.egg\pyramid_debugtoolbar\panels\performance.py", line 69, in noresource_timer_handler
result = handler(request)
File "D:\prg\py2\lib\site-packages\pyramid\tweens.py", line 21, in excview_tween
response = handler(request)
File "D:\prg\py2\lib\site-packages\pyramid_tm-0.7-py2.7.egg\pyramid_tm\__init__.py", line 82, in tm_tween
reraise(*exc_info)
File "D:\prg\py2\lib\site-packages\pyramid_tm-0.7-py2.7.egg\pyramid_tm\__init__.py", line 63, in tm_tween
response = handler(request)
File "D:\prg\py2\lib\site-packages\pyramid\router.py", line 161, in handle_request
response = view_callable(context, request)
File "D:\prg\py2\lib\site-packages\pyramid\config\views.py", line 367, in rendered_view
context)
File "D:\prg\py2\lib\site-packages\pyramid\renderers.py", line 531, in render_view
return self.render_to_response(response, system, request=request)
File "D:\prg\py2\lib\site-packages\pyramid\renderers.py", line 561, in render_to_response
result = self.render(value, system_values, request=request)
File "D:\prg\py2\lib\site-packages\pyramid\renderers.py", line 557, in render
result = renderer(value, system_values)
File "D:\prg\py2\lib\site-packages\pyramid\chameleon_zpt.py", line 42, in __call__
result = self.template(**system)
File "D:\prg\py2\lib\site-packages\chameleon\template.py", line 125, in __call__
return self.render(**kwargs)
File "D:\prg\py2\lib\site-packages\chameleon\zpt\template.py", line 257, in render
return super(PageTemplate, self).render(**vars)
File "D:\prg\py2\lib\site-packages\chameleon\template.py", line 190, in render
raise_with_traceback(exc, tb)
File "D:\prg\py2\lib\site-packages\chameleon\template.py", line 172, in render
self._render(stream, econtext, rcontext)
File "sprox_3aacd319285f07641f9292cdee192301f3a0bccd.py", line 136, in render
File "D:\prg\py2\lib\site-packages\chameleon\zpt\template.py", line 261, in include
self._render(*args, **kwargs)
File "template_f352de36cd7e76f81188f12078004a91a152cf44.py", line 376, in render
File "sprox_3aacd319285f07641f9292cdee192301f3a0bccd.py", line 106, in __fill_content
File "D:\prg\py2\lib\site-packages\sprox\viewbase.py", line 113, in __call__
return self.display(*args, **kw)
File "D:\prg\py2\lib\site-packages\sprox\viewbase.py", line 119, in display
return self.__widget__.display(*args, **kw)
File "D:\prg\py2\lib\site-packages\tw2\core\widgets.py", line 438, in display
return self.generate_output(displays_on)
File "D:\prg\py2\lib\site-packages\tw2\core\widgets.py", line 475, in generate_output
mw,
File "D:\prg\py2\lib\site-packages\tw2\core\templating.py", line 204, in render
return callback(kwargs)
File "D:\prg\py2\lib\site-packages\tw2\core\templating.py", line 144, in <lambda>
return lambda kwargs: Markup(tmpl.render(**kwargs))
File "D:\prg\py2\lib\site-packages\mako\template.py", line 412, in render
return runtime._render(self, self.callable_, args, data)
File "D:\prg\py2\lib\site-packages\mako\runtime.py", line 766, in _render
**_kwargs_for_callable(callable_, data))
File "D:\prg\py2\lib\site-packages\mako\runtime.py", line 798, in _render_context
_exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
File "D:\prg\py2\lib\site-packages\mako\runtime.py", line 824, in _exec_template
callable_(context, *args, **kwargs)
File "form_mak", line 49, in render_body
File "D:\prg\py2\lib\site-packages\tw2\core\widgets.py", line 436, in display
r.prepare()
File "D:\prg\py2\lib\site-packages\tw2\core\resources.py", line 165, in prepare
resources = rl['middleware'].resources
KeyError: 'middleware'
- Expression: "form(form_input)"
- Filename: d:\prg\py2\awsalloc2\awsalloc2\templates\sprox.pt
- Location: (9:28)
- Source: ... v tal:content="structure form(form_input)" />
^^^^^^^^^^^^^^^^
- Arguments: repeat: {...} (0)
renderer_name: templates/sprox.pt
req: <Request - at 0x46fceb8L>
form: <SproxForm - at 0x471cb38L>
request: <Request - at 0x46fceb8L>
renderer_info: <RendererHelper - at 0x4a3b7b8L>
context: <instance None at 0x4f93c88L>
form_input: {...} (0)
view: <function sprox_form_add at 0x4a3d278L>

I have no idea what your real problem is, but I threw together a little demo to demonstrate how to setup Sprox under Pyramid. It was somewhat painful and uses some idioms that I consider pretty outdated, including requiring Paste, SQLAlchemy < 0.8, Genshi, and ToscaWidgets < 2.0. Hope this helps.
If I had to guess, you aren't adding the middleware to your app.
app = tw.api.make_middleware(
app,
{
'toscawidgets.framework' : 'wsgi',
'toscawidgets.middleware.inject_resources' : True,
},
stack_registry=True,
)
https://github.com/mmerickel/pyramid_sprox_demo

Related

mkdocstrings: ERROR - Error reading page 'codereference.md': <class '_ast.ExtSlice'>

I obtain the following error when typing mkdocs serve in terminal:
ERROR - Error reading page 'codereference.md': <class '_ast.ExtSlice'>
(with a very long traceback, see below)
My mkdocs.yaml file is:
site_name: Code Documentation
site_url: https://example.com/
nav:
- Home: index.md
- About: about.md
- Code: codereference.md
theme: readthedocs
plugins:
- mkdocstrings:
handlers:
python:
paths: [.]
The codereference.md file consists of the following:
# Reference
::: path.to.class.from.where.mkdocsyaml.is
Anybody have any possible answers?
The full traceback is:
Traceback (most recent call last):
File "/usr/local/bin/mkdocs", line 8, in <module>
sys.exit(cli())
File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 1130, in __call__
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 1055, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 1657, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 760, in invoke
return __callback(*args, **kwargs)
File "/usr/local/lib/python3.8/dist-packages/mkdocs/__main__.py", line 181, in serve_command
serve.serve(dev_addr=dev_addr, livereload=livereload, watch=watch, **kwargs)
File "/usr/local/lib/python3.8/dist-packages/mkdocs/commands/serve.py", line 63, in serve
config = builder()
File "/usr/local/lib/python3.8/dist-packages/mkdocs/commands/serve.py", line 58, in builder
build(config, live_server=live_server, dirty=dirty)
File "/usr/local/lib/python3.8/dist-packages/mkdocs/commands/build.py", line 292, in build
_populate_page(file.page, config, files, dirty)
File "/usr/local/lib/python3.8/dist-packages/mkdocs/commands/build.py", line 174, in _populate_page
page.render(config, files)
File "/usr/local/lib/python3.8/dist-packages/mkdocs/structure/pages.py", line 175, in render
self.content = md.convert(self.markdown)
File "/usr/local/lib/python3.8/dist-packages/markdown/core.py", line 264, in convert
root = self.parser.parseDocument(self.lines).getroot()
File "/usr/local/lib/python3.8/dist-packages/markdown/blockparser.py", line 90, in parseDocument
self.parseChunk(self.root, '\n'.join(lines))
File "/usr/local/lib/python3.8/dist-packages/markdown/blockparser.py", line 105, in parseChunk
self.parseBlocks(parent, text.split('\n\n'))
File "/usr/local/lib/python3.8/dist-packages/markdown/blockparser.py", line 123, in parseBlocks
if processor.run(parent, blocks) is not False:
File "/usr/local/lib/python3.8/dist-packages/mkdocstrings/extension.py", line 121, in run
html, handler, data = self._process_block(identifier, block, heading_level)
File "/usr/local/lib/python3.8/dist-packages/mkdocstrings/extension.py", line 195, in _process_block
data: CollectorItem = handler.collect(identifier, options)
File "/usr/local/lib/python3.8/dist-packages/mkdocstrings_handlers/python/handler.py", line 191, in collect
loader.load_module(module_name)
File "/usr/local/lib/python3.8/dist-packages/griffe/loader.py", line 148, in load_module
top_module = self._load_module(package.name, package.path, submodules=submodules)
File "/usr/local/lib/python3.8/dist-packages/griffe/loader.py", line 352, in _load_module
return self._load_module_path(module_name, module_path, submodules, parent)
File "/usr/local/lib/python3.8/dist-packages/griffe/loader.py", line 380, in _load_module_path
self._load_submodules(module)
File "/usr/local/lib/python3.8/dist-packages/griffe/loader.py", line 385, in _load_submodules
self._load_submodule(module, subparts, subpath)
File "/usr/local/lib/python3.8/dist-packages/griffe/loader.py", line 396, in _load_submodule
member_parent[subparts[-1]] = self._load_module(
File "/usr/local/lib/python3.8/dist-packages/griffe/loader.py", line 352, in _load_module
return self._load_module_path(module_name, module_path, submodules, parent)
File "/usr/local/lib/python3.8/dist-packages/griffe/loader.py", line 374, in _load_module_path
module = self._visit_module(code, module_name, module_path, parent)
File "/usr/local/lib/python3.8/dist-packages/griffe/loader.py", line 413, in _visit_module
module = visit(
File "/usr/local/lib/python3.8/dist-packages/griffe/agents/visitor.py", line 92, in visit
return Visitor(
File "/usr/local/lib/python3.8/dist-packages/griffe/agents/visitor.py", line 172, in get_module
self.visit(top_node)
File "/usr/local/lib/python3.8/dist-packages/griffe/agents/visitor.py", line 183, in visit
super().visit(node)
File "/usr/local/lib/python3.8/dist-packages/griffe/agents/base.py", line 19, in visit
getattr(self, f"visit_{node.kind}", self.generic_visit)(node) # type: ignore[attr-defined]
File "/usr/local/lib/python3.8/dist-packages/griffe/agents/visitor.py", line 214, in visit_module
self.generic_visit(node)
File "/usr/local/lib/python3.8/dist-packages/griffe/agents/visitor.py", line 196, in generic_visit
self.visit(child)
File "/usr/local/lib/python3.8/dist-packages/griffe/agents/visitor.py", line 183, in visit
super().visit(node)
File "/usr/local/lib/python3.8/dist-packages/griffe/agents/base.py", line 19, in visit
getattr(self, f"visit_{node.kind}", self.generic_visit)(node) # type: ignore[attr-defined]
File "/usr/local/lib/python3.8/dist-packages/griffe/agents/visitor.py", line 255, in visit_classdef
self.generic_visit(node)
File "/usr/local/lib/python3.8/dist-packages/griffe/agents/visitor.py", line 196, in generic_visit
self.visit(child)
File "/usr/local/lib/python3.8/dist-packages/griffe/agents/visitor.py", line 183, in visit
super().visit(node)
File "/usr/local/lib/python3.8/dist-packages/griffe/agents/base.py", line 19, in visit
getattr(self, f"visit_{node.kind}", self.generic_visit)(node) # type: ignore[attr-defined]
File "/usr/local/lib/python3.8/dist-packages/griffe/agents/visitor.py", line 451, in visit_functiondef
self.handle_function(node)
File "/usr/local/lib/python3.8/dist-packages/griffe/agents/visitor.py", line 442, in handle_function
self.generic_visit(node)
File "/usr/local/lib/python3.8/dist-packages/griffe/agents/visitor.py", line 196, in generic_visit
self.visit(child)
File "/usr/local/lib/python3.8/dist-packages/griffe/agents/visitor.py", line 183, in visit
super().visit(node)
File "/usr/local/lib/python3.8/dist-packages/griffe/agents/base.py", line 19, in visit
getattr(self, f"visit_{node.kind}", self.generic_visit)(node) # type: ignore[attr-defined]
File "/usr/local/lib/python3.8/dist-packages/griffe/agents/visitor.py", line 589, in visit_assign
self.handle_attribute(node)
File "/usr/local/lib/python3.8/dist-packages/griffe/agents/visitor.py", line 548, in handle_attribute
value = get_value(node.value) # type: ignore[arg-type]
File "/usr/local/lib/python3.8/dist-packages/griffe/agents/nodes.py", line 1181, in get_value
return _node_value_map[type(node)](node)
File "/usr/local/lib/python3.8/dist-packages/griffe/agents/nodes.py", line 1047, in _get_subscript_value
subscript = _get_value(node.slice)
File "/usr/local/lib/python3.8/dist-packages/griffe/agents/nodes.py", line 1167, in _get_value
return _node_value_map[type(node)](node)
KeyError: <class '_ast.ExtSlice'>
It's fixed in version 0.21.0 of Griffe: https://mkdocstrings.github.io/griffe/changelog/#bug-fixes
It would previously crash when unparsing values using extended slices such as o[x:y,z].

Django Error - AttributeError: 'CourseOverview' object has no attribute 'start_datetime_text'

I have been trying to get this theme working for Open edX (based on Django) and I am getting this error in supervisor logs -
AttributeError: 'CourseOverview' object has no attribute 'start_datetime_text'
The whole error is this -
May 14 11:43:36 ip-172-26-15-154 [service_variant=lms][django.request][env:sandbox] ERROR [ip-172-26-15-154 20450] [base.py:256] - Internal Server Error: /
Traceback (most recent call last):
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 132, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/utils/decorators.py", line 145, in inner
return func(*args, **kwargs)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/utils/decorators.py", line 110, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/edx/app/edxapp/edx-platform/common/djangoapps/util/cache.py", line 78, in wrapper
response = view_func(request, *args, **kwargs)
File "/edx/app/edxapp/edx-platform/lms/djangoapps/branding/views.py", line 94, in index
return student.views.index(request, user=request.user)
File "/edx/app/edxapp/edx-platform/common/djangoapps/student/views.py", line 221, in index
return render_to_response('index.html', context)
File "/edx/app/edxapp/edx-platform/common/djangoapps/edxmako/shortcuts.py", line 198, in render_to_response
return HttpResponse(render_to_string(template_name, dictionary, context_instance, namespace, request), **kwargs)
File "/edx/app/edxapp/edx-platform/common/djangoapps/edxmako/shortcuts.py", line 188, in render_to_string
return template.render_unicode(**context_dictionary)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/mako/template.py", line 454, in render_unicode
as_unicode=True)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/mako/runtime.py", line 829, in _render
**_kwargs_for_callable(callable_, data))
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/mako/runtime.py", line 864, in _render_context
_exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/mako/runtime.py", line 890, in _exec_template
callable_(context, *args, **kwargs)
File "/tmp/mako_lms/c11f9c5f254718c770fcf021e95ac093/main.html.py", line 286, in render_body
__M_writer(filters.decode.utf8(self.body()))
File "/tmp/mako_lms/c11f9c5f254718c770fcf021e95ac093/marvel-theme-eucalyptus/lms/templates/index.html.py", line 54, in render_body
runtime._include_file(context, (courses_list), _template_uri)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/mako/runtime.py", line 752, in _include_file
callable_(ctx, **_kwargs_for_include(callable_, context._data, **kwargs))
File "/tmp/mako_lms/c11f9c5f254718c770fcf021e95ac093/marvel-theme-eucalyptus/lms/templates/courses_list.html.py", line 44, in render_body
runtime._include_file(context, u'course.html', _template_uri, course=course)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/mako/runtime.py", line 752, in _include_file
callable_(ctx, **_kwargs_for_include(callable_, context._data, **kwargs))
File "/tmp/mako_lms/c11f9c5f254718c770fcf021e95ac093/marvel-theme-eucalyptus/lms/templates/course.html.py", line 60, in render_body
__M_writer(filters.html_escape(filters.decode.utf8(course.start_datetime_text())))
AttributeError: 'CourseOverview' object has no attribute 'start_datetime_text'
The file in question (the one that is giving the error - course.html.py) is here
https://pastebin.com/0S79hhDa
The start_datetime_text method was removed on november 30, 2016.
You should be using course.advertised_start. You can see the current version of the course.html template

Can't use API with username and password in Scrapy

This Curl works.
https://<user>:<pass>#xecdapi.xe.com/v1/convert_from.json/?from=1000000&to=SGD&amount=AED,AUD,BDT&inverse=True
But this Scrapy request doesn't work.
yield scrapy.Request("https://<user>:<pass>#xecdapi.xe.com/v1/convert_from.json/?from=1000000&to=SGD&amount=AED,AUD,BDT&inverse=True")
It returns this error:
Traceback (most recent call last):
File "d:\kerja\hit\python~1\<project_name>\<project_name>\lib\site-packages\twisted\internet\defer.py", line 1297, in _inlineCallbacks
result = result.throwExceptionIntoGenerator(g)
File "d:\kerja\hit\python~1\<project_name>\<project_name>\lib\site-packages\twisted\python\failure.py", line 389, in throwExceptionIntoGenerator
return g.throw(self.type, self.value, self.tb)
File "d:\kerja\hit\python~1\<project_name>\<project_name>\lib\site-packages\scrapy\core\downloader\middleware.py", line 43, in process_request
defer.returnValue((yield download_func(request=request,spider=spider)))
File "d:\kerja\hit\python~1\<project_name>\<project_name>\lib\site-packages\scrapy\utils\defer.py", line 45, in mustbe_deferred
result = f(*args, **kw)
File "d:\kerja\hit\python~1\<project_name>\<project_name>\lib\site-packages\scrapy\core\downloader\handlers\__init__.py", line 65, in download_request
return handler.download_request(request, spider)
File "d:\kerja\hit\python~1\<project_name>\<project_name>\lib\site-packages\scrapy\core\downloader\handlers\http11.py", line 61, in download_request
return agent.download_request(request)
File "d:\kerja\hit\python~1\<project_name>\<project_name>\lib\site-packages\scrapy\core\downloader\handlers\http11.py", line 286, in download_request
method, to_bytes(url, encoding='ascii'), headers, bodyproducer)
File "d:\kerja\hit\python~1\<project_name>\<project_name>\lib\site-packages\twisted\web\client.py", line 1596, in request
endpoint = self._getEndpoint(parsedURI)
File "d:\kerja\hit\python~1\<project_name>\<project_name>\lib\site-packages\twisted\web\client.py", line 1580, in _getEndpoint
return self._endpointFactory.endpointForURI(uri)
File "d:\kerja\hit\python~1\<project_name>\<project_name>\lib\site-packages\twisted\web\client.py", line 1456, in endpointForURI
uri.port)
File "d:\kerja\hit\python~1\<project_name>\<project_name>\lib\site-packages\scrapy\core\downloader\contextfactory.py", line 59, in creatorForNetloc
return ScrapyClientTLSOptions(hostname.decode("ascii"), self.getContext())
File "d:\kerja\hit\python~1\<project_name>\<project_name>\lib\site-packages\twisted\internet\_sslverify.py", line 1201, in __init__
self._hostnameBytes = _idnaBytes(hostname)
File "d:\kerja\hit\python~1\<project_name>\<project_name>\lib\site-packages\twisted\internet\_sslverify.py", line 87, in _idnaBytes
return idna.encode(text)
File "d:\kerja\hit\python~1\<project_name>\<project_name>\lib\site-packages\idna\core.py", line 355, in encode
result.append(alabel(label))
File "d:\kerja\hit\python~1\<project_name>\<project_name>\lib\site-packages\idna\core.py", line 276, in alabel
check_label(label)
File "d:\kerja\hit\python~1\<project_name>\<project_name>\lib\site-packages\idna\core.py", line 253, in check_label
raise InvalidCodepoint('Codepoint {0} at position {1} of {2} not allowed'.format(_unot(cp_value), pos+1, repr(label)))
InvalidCodepoint: Codepoint U+003A at position 28 of u'xxxxxxxxxxxxxxxxxxxxxxxxxxxx:xxxxxxxxxxxxxxxxxxxxxxxxxxx#xecdapi' not allowed
Scrapy does not support HTTP Authentication via URL. We have to use HTTPAuthMiddleware instead.
in settings.py:
DOWNLOADER_MIDDLEWARES = {
'scrapy.downloadermiddlewares.httpauth.HttpAuthMiddleware': 811,
}
in the spider:
from scrapy.spiders import CrawlSpider
class SomeIntranetSiteSpider(CrawlSpider):
http_user = 'someuser'
http_pass = 'somepass'
name = 'intranet.example.com'
# .. rest of the spider code omitted ...

How to resolve TemplateSyntaxError: Could not parse the remainder error?

I'm getting a "TemplateSyntaxError: Could not parse the remainder:" here: https://docs.djangoproject.com/en/1.7/intro/tutorial05/
>>> response = client.get(reverse('polls:index'))
gets me this:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Library/Python/2.7/site-packages/django/test/client.py", line 470, in get
**extra)
File "/Library/Python/2.7/site-packages/django/test/client.py", line 286, in get
return self.generic('GET', path, secure=secure, **r)
File "/Library/Python/2.7/site-packages/django/test/client.py", line 358, in generic
return self.request(**r)
File "/Library/Python/2.7/site-packages/django/test/client.py", line 440, in request
six.reraise(*exc_info)
File "/Library/Python/2.7/site-packages/django/core/handlers/base.py", line 137, in get_response
response = response.render()
File "/Library/Python/2.7/site-packages/django/template/response.py", line 103, in render
self.content = self.rendered_content
File "/Library/Python/2.7/site-packages/django/template/response.py", line 78, in rendered_content
template = self.resolve_template(self.template_name)
File "/Library/Python/2.7/site-packages/django/template/response.py", line 54, in resolve_template
return loader.select_template(template)
File "/Library/Python/2.7/site-packages/django/template/loader.py", line 188, in select_template
return get_template(template_name, dirs)
File "/Library/Python/2.7/site-packages/django/template/loader.py", line 144, in get_template
template, origin = find_template(template_name, dirs)
File "/Library/Python/2.7/site-packages/django/template/loader.py", line 132, in find_template
source, display_name = loader(name, dirs)
File "/Library/Python/2.7/site-packages/django/template/loader.py", line 44, in __call__
return self.load_template(template_name, template_dirs)
File "/Library/Python/2.7/site-packages/django/template/loader.py", line 50, in load_template
template = get_template_from_string(source, origin, template_name)
File "/Library/Python/2.7/site-packages/django/template/loader.py", line 156, in get_template_from_string
return Template(source, origin, name)
File "/Library/Python/2.7/site-packages/django/template/base.py", line 132, in __init__
self.nodelist = compile_string(template_string, origin)
File "/Library/Python/2.7/site-packages/django/template/base.py", line 162, in compile_string
return parser.parse()
File "/Library/Python/2.7/site-packages/django/template/base.py", line 290, in parse
compiled_result = compile_func(self, token)
File "/Library/Python/2.7/site-packages/django/template/defaulttags.py", line 975, in do_if
nodelist = parser.parse(('elif', 'else', 'endif'))
File "/Library/Python/2.7/site-packages/django/template/base.py", line 290, in parse
compiled_result = compile_func(self, token)
File "/Library/Python/2.7/site-packages/django/template/defaulttags.py", line 833, in do_for
nodelist_loop = parser.parse(('empty', 'endfor',))
File "/Library/Python/2.7/site-packages/django/template/base.py", line 290, in parse
compiled_result = compile_func(self, token)
File "/Library/Python/2.7/site-packages/django/template/defaulttags.py", line 1345, in url
viewname = parser.compile_filter(bits[1])
File "/Library/Python/2.7/site-packages/django/template/base.py", line 372, in compile_filter
return FilterExpression(token, self)
File "/Library/Python/2.7/site-packages/django/template/base.py", line 588, in __init__
"from '%s'" % (token[upto:], token))
TemplateSyntaxError: Could not parse the remainder: '\u2018polls:detail\u2019' from '\u2018polls:detail\u2019'
How to resolve this ?
You are using left quote and right quote characters when quoting the view name; where you should be using single or double quotes.
Use either 'polls:details' or "polls:details"

Pyramid Python: nonetype error in urldispatch

pyramid/url.py seems to have a bug. Here is the code
import os
from wsgiref.simple_server import make_server
from pyramid.config import Configurator
from pyramid.response import Response
from pyramid.view import view_config
here = os.path.dirname(os.path.abspath(__file__))
#view_config(route_name='firstview',renderer='firstview.mako',request_method='GET')
def firstview(request):
return {'example':'text'}
#view_config(route_name='secondview',request_method='POST')
def secondview(request):
return Response('second view')
if __name__ == '__main__':
settings = {}
settings['mako.directories'] = os.path.join(here,'templates')
config = Configurator(settings=settings)
config.add_route('firstview','/firstview')
config.add_route('secondview','/secondview')
config.scan()
app = config.make_wsgi_app()
This is the template for firstview
# -*- coding: utf-8 -*-
<form name="example"
action="${request.route_url('secondview')}"
method="POST">
example
<textarea rows="4" cols="50" name="name">
</textarea><br>
<input type="submit" value="Submit">
</form>
And here is the stack trace
2013-06-10 21:05:40,280 - DEBUG - http://localhost:8080 #app_url
2013-06-10 21:05:40,280 - DEBUG - None #path
2013-06-10 21:05:40,280 - DEBUG - #suffix
2013-06-10 21:05:40,280 - DEBUG - #qs
2013-06-10 21:05:40,280 - DEBUG - #anchorTraceback (most recent call last):
File "/Users/abc/env/bin/lib/python2.7/wsgiref/handlers.py", line 85, in run
self.result = application(self.environ, self.start_response) File "/Users/abc/env/bin/lib/python2.7/site-packages/pyramid-1.4.1-py2.7.egg/pyramid/router.py", line 251, in __call__
response = self.invoke_subrequest(request, use_tweens=True)
File "/Users/abc/env/bin/lib/python2.7/site-packages/pyramid-1.4.1-py2.7.egg/pyramid/router.py", line 227, in invoke_subrequest response = handle_request(request)
File "/Users/abc/env/bin/lib/python2.7/site-packages/pyramid-1.4.1-py2.7.egg/pyramid/tweens.py", line 21, in excview_tween
response = handler(request) File "/Users/abc/env/bin/lib/python2.7/site-packages/pyramid-1.4.1-py2.7.egg/pyramid/router.py", line 161, in handle_request
response = view_callable(context, request)
File "/Users/abc/env/bin/lib/python2.7/site-packages/pyramid-1.4.1-py2.7.egg/pyramid/config/views.py", line 321, in attr_view return view(context, request)
File "/Users/abc/env/bin/lib/python2.7/site-packages/pyramid-1.4.1-py2.7.egg/pyramid/config/views.py", line 297, in predicate_wrapper
return view(context, request) File "/Users/abc/env/bin/lib/python2.7/site-packages/pyramid-1.4.1-py2.7.egg/pyramid/config/views.py", line 369, in rendered_view
context)
File "/Users/abc/env/bin/lib/python2.7/site-packages/pyramid-1.4.1-py2.7.egg/pyramid/renderers.py", line 531, in render_view return self.render_to_resp
onse(response, system, request=request)
File "/Users/abc/env/bin/lib/python2.7/site-packages/pyramid-1.4.1-py2.7.egg/pyramid/renderers.py", line 561, in render_to_response
result = self.render(value, system_values, request=request)
File "/Users/abc/env/bin/lib/python2.7/site-packages/pyramid-1.4.1-py2.7.egg/pyramid/renderers.py", line 557, in render
result = renderer(value, system_values)
File "/Users/abc/env/bin/lib/python2.7/site-packages/pyramid-1.4.1-py2.7.egg/pyramid/mako_templating.py", line 215, in __call__
reraise(MakoRenderingException(errtext), None, exc_info[2])
File "/Users/abc/env/bin/lib/python2.7/site-packages/pyramid-1.4.1-py2.7.egg/pyramid/mako_templating.py", line 207, in __call__
result = template.render_unicode(**system)
File "/Users/abc/env/bin/lib/python2.7/site-packages/Mako-0.8.0-py2.7.egg/mako/template.py", line 452, in render_unicode
as_unicode=True)
File "/Users/abc/env/bin/lib/python2.7/site-packages/Mako-0.8.0-py2.7.egg/mako/runtime.py", line 783, in _render
**_kwargs_for_callable(callable_, data))
File "/Users/abc/env/bin/lib/python2.7/site-packages/Mako-0.8.0-py2.7.egg/mako/runtime.py", line 815, in _render_context
_exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
File "/Users/abc/env/bin/lib/python2.7/site-packages/Mako-0.8.0-py2.7.egg/mako/runtime.py", line 841, in _exec_template
callable_(context, *args, **kwargs)
File "firstview_mako", line 23, in render_body
File "/Users/abc/env/bin/lib/python2.7/site-packages/pyramid-1.4.1-py2.7.egg/pyramid/url.py", line 267, in route_url
return app_url + path + suffix + qs + anchor
MakoRenderingException:
Traceback (most recent call last):
File "/Users/abc/env/bin/lib/python2.7/site-packages/pyramid-1.4.1-py2.7.egg/pyramid/mako_templating.py", line 207, in __call__
result = template.render_unicode(**system)
File "/Users/abc/env/bin/lib/python2.7/site-packages/Mako-0.8.0-py2.7.egg/mako/template.py", line 452, in render_unicode
as_unicode=True)
File "/Users/abc/env/bin/lib/python2.7/site-packages/Mako-0.8.0-py2.7.egg/mako/runtime.py", line 783, in _render
**_kwargs_for_callable(callable_, data))
File "/Users/abc/env/bin/lib/python2.7/site-packages/Mako-0.8.0-py2.7.egg/mako/runtime.py", line 815, in _render_context
_exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
File "/Users/abc/env/bin/lib/python2.7/site-packages/Mako-0.8.0-py2.7.egg/mako/runtime.py", line 841, in _exec_template
callable_(context, *args, **kwargs)
File "/Users/abc/piramide/bugreplica/templates/firstview.mako", line 3, in render_body
action="${request.route_url('secondview')}"
File "/Users/abc/env/bin/lib/python2.7/site-packages/pyramid-1.4.1-py2.7.egg/pyramid/url.py", line 267, in route_url
return app_url + path + suffix + qs + anchor
TypeError: cannot concatenate 'str' and 'NoneType' objects
Since I added some lines for debugging purpose the line number will be different.
Anyway, I noticed that path returns None. In the code there is no handling of this case. I am new to the pyramid framework, I would appreciate your help. Thanks!
P.S.
Apparently this problem stems from url.py's function route_url. Specifically route.pregenerator(self, elements, kw) returns None and there is no handling of this case.

Categories

Resources