zope template namespaces gone? - python

Where can I find the zope namespaces for my templates? I setup a pyramid project using SQLAlchemy + URL dispatch + Chameleon templates. These URLs don't exist anymore...
http://xml.zope.org/namespaces/tal
http://xml.zope.org/namespaces/metal
Thanks.

The TAL specification says:
This is not a URL, but merely a unique identifier. Do not expect a browser to resolve it successfully.
http://wiki.zope.org/ZPT/TALSpecification14

Related

How do I get FastAPI to do SSR for Vue 3?

According to this documentation for Vue's SSR, it is possible to use node.js to render an app and return it using an express server. Is is possible to do the same with FastAPI?
Or is using Jinja2 templates or SPA the only solution?
Problems:
No SPA: To help with SEO
No SSG: Too many pages will be generated. Some need to be generated dynamically.
No Jinja2/Python Templates: Node modules aren't built, bundled and served. All modules have to served from a remote package CDN.
I have a feeling that maybe changing the Vue 3 delimiters and then building the project and serving the files as Jinja2 templates is the solution, but I'm not sure how it would work with Vue's routers. I know the /dist folder can be served on the default route and then use a catchall can be used to display files that do exist.
Possible Solution
#app.get("/", response_class=FileResponse)
def read_index(request: Request):
index = f"{static_folder}/index.html"
return FileResponse(index)
#app.get("/{catchall:path}", response_class=FileResponse)
def read_index(request: Request):
path = request.path_params["catchall"]
file = static_folder + path
if os.path.exists(file):
return FileResponse(file)
index = f"{static_folder}/index.html"
return FileResponse(index)
Questions
If there is a way to do SSR with FastAPI and Vue 3, what is it?
If there is no direct way, how do I combine Vue's built /dist with Jinja2 templates to serve dynamic pages?
There are several options available, such as Nuxt.js, Quasar, and Gridsome, which provide support for SSR with FastAPI and Vue 3.

Flask app rendering some variable urls from HTML docs in folder but not others HTML docs in the same folder

My Flask app renders all templates in the template folder, including all blog posts in a blog folder within the templates folder. However, I have the exact structure for my app's glossary as I have for the blog - a folder called 'glossary' within the templates folder. But, it's quirky. It renders some html documents but not others from that same folder. It renders 0-day.html every time I click a link with that dynamic url or directly type in /0-day; but not act.html using /act. I have 180 html files in the glossary folder and about half render and the rest return a 404.
I've been researching this for a month now, and today I switched the glossary structure by creating a blueprint instead. I used this tutorial: https://www.youtube.com/watch?v=WteIH6J9v64. I got everything running as normal, except the same issue with the glossary persists with the blueprint setup as well.
Assuming everything else works, and it does:
Glossary Term:
#glossary.route("<termname>", methods=["POST","GET"])
def term(termname='story'):
try:
visits(termname)
return render_template(f"{termname}.html", glossary=True, termname=termname)
except Exception as e:
return page_not_found(e)
As you can see below, I have my blog setup the same way:
Blog Posts
#app.route("/blog/<postname>", methods=["POST","GET"])
def post(postname='distant-idealism-introduction'):
try:
visits(postname)
return render_template(f"/blog/{postname}.html", blog=True, postname=postname)
except Exception as e:
return page_not_found(e)
The only difference is that the blog is routed from the routes.py now and the glossary terms from the glossary.py blueprint. However, when there was no blueprint I was rendering everything from the routes.py file, so the blueprint setup is not the cause.
I apologize, but because this problem is so confusing, I don't know what else to add. It's even difficult to research because I always get results like the YouTube video above - either about blueprints, building routes, or something Flask in general. I never get any search result even close to my issue. If more info is required just let me know, please.
Thank you in advance.
Some problems I found:
The URL rule is missing a start slash:
#glossary.route("/<termname>", methods=["POST","GET"])
Since your templates about glossaries were put in a glossary folder, your template path should be /glossary/act.html:
return render_template(f"/glossary/{termname}.html", glossary=True, termname=termname)

How to get the name of the Flask blueprint inside a template?

I have a site built with Flask. It has several sections, each with a dedicated blueprint. The templates in each blueprint extend a base template, which has the basic layout for each page, including a navigation bar with tabs for each section.
I'd like to have the base template highlight the current tab, so it needs to know which blueprint's view is handling the request.
One way I came up with to do this is to add a before_request handler to each blueprint and store the name in g:
bp = Blueprint('blog', __name__, url_prefix='/blog')
#bp.before_request
def set_bp_name():
g.section = 'blog'
But Flask must know which blueprint is handling a request (if any) and the blueprint, of course, knows its own name. Is there a way for the template to fetch the current blueprint's name that doesn't require modifying each blueprint?
Yes. Quite simply: request.blueprint.
The request object is one of a few (along with g) that Flask makes available to all templates. It contains the blueprint property, which is the name of the blueprint handling the current request.

How does Django build URLs that depend on a site?

I am trying to find out how does Django build URLs, especially those that depend on multiple sites. Where does Django build URLs and how is the site domain prepended to the user defined URL patterns?
Basically, I have several Django CMS pages and multiple Django sites. I need to know how are the URLs created for a page that relies on a different site than the current site; namely, how is the correct site's domain added to a page's URL.
Seems like, adding a Django site's domain to the URL has to be done manually. From Django's docs:
>>> from django.contrib.sites.models import Site
>>> obj = MyModel.objects.get(id=3)
>>> obj.get_absolute_url()
'/mymodel/objects/3/'
>>> Site.objects.get_current().domain
'example.com'
>>> 'http://%s%s' % (Site.objects.get_current().domain, obj.get_absolute_url())
'http://example.com/mymodel/objects/3/'

Pylons + Mako -- Access POST data from templates

How can I access my request.params post data from my Mako template with Pylons?
Same as in the controller.
${request.params['my_param']}
or preferably:
${request.params.get('my_param', '')}

Categories