I created a personal CMS project where each page is stored in the database with the following columns: title, url_safe_title, and content.
To create the url_safe_title, I used urllib.parse.quote() on the original title. So if the page title is "My Page", the url_safe_title will be stored as "My%20Page".
On templates, I'd build URLs using url_for('core.page', page_name = page.url_safe_title), where page_name is the expected variable in the view function.
#core.route('/<string:page_name>')
def page(page_name):
# find the relevant entry in db
return render_template('template.html', page = page)
However, the resulting URL becomes "www.example.com/My%2520Page" instead of the expected "www.example.com/My%20Page". I checked the url_safe_title value stored in the database, and it's the correct value ("My%20Page").
Interestingly, "My%2520Page" worked when trying to query for a page that has url_safe_title as "My%20Page" when I was hosting this app locally. However, it all fell apart when I hosted it online. Unfortunately, the host is a limited cPanel host without any access to the terminal, so I'm unable to find out what the OS is. I only know that the python version is 3.7.8, and my local python version is 3.7.4.
I've also tried using the |safe jinja filter when building the URL url_for('core.page', page_name = page.url_safe_title|safe), but that didn't help either. I passed the page.url_safe_title as a variable on its on to show on the page, and "My%20Page" was displayed.
%2520 means it is getting encoded twice. You should not encode it before storing in the database. It is just a string.
Related
I have a small flask application that I'm running on localhost right now. most things are working fine but I've been banging my head for last few hours over this issue now - When I try to put an external link on my template, it always redirects to localhost.
I have a main.py file where I have placed a variable
testURL = "https://www.google.com"
On my template file, home.html, I place the hyperlink
More...
Clicking on that 'More...' hyperlink I wanted it to open a new tab to google.com but it's simply opening up a new tab with localhost http://127.0.0.1:5000/ - it's something very basic that I'm missing on I think.
Please point me in the right direction!
TIA
As mentioned, you need to pass that variable to the template:
render_template('home.html', testURL=testURL)
Another useful method, if you want to send that variable to every page, is to use a context processor:
#app.context_processor
def processor():
""" This function injects vars into every page """
return dict(SITE_TITLE='My Site')
Then use {{SITE_TITLE}} in any template.
I use opencart version 2.1.0.1
Everytime I click admin > sales > order, it will pop up "error undefined." By closing that popup window, I can still edit order but cannot delete order (no response).
In my log, there is:
PHP Notice: Undefined variable: order_id in
/var/www/html/opencart2101/system/storage/modification/admin/view/template/sale/order_list.tpl on line 821
The line 821 is:
url: 'index.php?route=extension/openbay/addorderinfo&token=<?php echo $token; ?>&order_id=<?php echo $order_id; ?>&status_id=' + status_id,
However, I haven't installed any openbay related module. Also, line 821 is inside <!-- --> mark. It should have no effect.
Help!
Although this is now an older version of opencart, I still see this being reported a lot around and about.
The problem occurs due to the store front adding the http url rather than the https url to the order. So firstly you need to fix that. If you dont want to read all of my explanation, you can just hit up the bold points :)
Either way BACKUP EVERYTHING actually not really, back up the file you are going to edit and backup your whole database.
open:
catalog/controller/checkout/confirm.php at around line 100
Find:
$order_data['store_url'] = HTTP_SERVER;
Change to:
$order_data['store_url'] = HTTPS_SERVER;
Now you will want to fix your database because for reasons I cannot fathom, the domain name is placed in the order along with the stores id. and when editing orders it is the usage of that directly within your admin order page that throws up the undefined notice. Basically the browser blocks the request because its trying to make an insecure request from a secure page.
Crack open phpmyadmin or whatever database tool you have on hand.
locate the table, default is oc_orders
Browsing the table, look for the column that contains your store url (i cant remember the name off hand, i think its just store_url but it will be obvious anyway. if you are multi store you will need to run the query for each
I am sure somebody can come up with a clever way to automatically convert just the http into https with a single use sql query on the one column, but this works for me.
Run SQL: adjust as appropriate
UPDATE `oc_orders` SET `store_url` = 'https://example.com' WHERE store_id = 0;
I've created a new page Aikau, but I changed the XML file and the rendered page content between the standard Share header and footer disappeared.
In this page, I want the arguments of the query string, so I write this code:
page.get.desc.xml:
<webscript>
<shortname>My New Page</shortname>
<url>/hdp/ws/my-new-page</url>
<authentication>user</authentication>
</webscript>
page.get.js:
function main ()
{
// Get the args
var fileProp = args["test"];
model.temp = fileProp;
}
main();
page.get.html.ftl:
Test arg: ${temp}
I have to put /hdp/ws/my-new-page in the XML file to write the content of FTL file in this page... But why did the header and footer of the Alfresco template disappeared ? hdp serves for this purpose. And if I don't put the URL like that on the XML, the page appears with the template.
What is wrong in my code? Or how can I recover the template? Or add header and footer?
EDIT: I already try to put only /my-new-page without /hdp/ws/ but the args are null when I put /hdp/ws/. Give me a hint.
EDIT2: I already try to import alfresco-template.ftl but I can't. Any idea?
You don't actually need to include the the "hdp/ws" part in your WebScript descriptor. Only the "/my-new-page" is required. Aikau attempts to simplify the Surf page creation by providing a number of pages out-of-the-box (and the "hdp" page is just one of them).
Aikau uses URI-template mapping to match a single WebScript to a page, so for example in the URL:
/share/page/hdp/ws/my-new-page
share = application context
page = Spring MVC request dispatcher
hdp/ws/my-new-page is then mapped to the URI template:
<uri-template id="share-page">/{pageid}/ws/{webscript}</uri-template>
Where "hdp" is the id of the page to render and "my-new-page" is the WebScript URL. The HDP page uses the "webscript" token from the template to automatically create a new Surf Component and bind it to the WebScript.
But in short - don't include "hdp/ws" in your WebScript URLs for Aikau pages.
You need to make the things that you have on javascript server in this javascript mandatorily? If not, you can create a javascript client that receive the same arguments (location.search give to you the query string, so, you can make parse of that query string and get only the value of the "test" that you want) and call them on FTL file (the client-side javascript). So, when the page loading, it does not lose the arguments. It isn't the best solution but you can try this...
I have a trouble in sharepoint search.
I have dev environment and customize the Core search web part results.
The results view changed with xlst. In xslt i use HitHighlighting template for highlighting search results and jquery for replacing # symbols.
On dev environment search site work great, but when I moved my settings to test environment some functionality doesn't work.
Search works with title in query, with query includes title and some properties, but doesn't work with query includes title with some other properties.
I tried to output search raw result and all of searched properties are in raw result. But when I use query like title and one of "problem" property the raw result return empty.
Why sharepoint search returns no result on query with "problem" property and return this property in raw result with title search query.
Where can be the difference in my environments?
I resolve my problem.
At test environment I delete Search service with database from services in CA.
Then I create a new one and configured it. Search start works properly.
I am trying to use Cloudinary as a CDN and am having some trouble getting file uploads to work properly. I have followed their blog posts and website, but am running into a consistent and very annoying error.
I have a model associated with both an image (a cover photo) and a media object (a PDF or ebook, like a .mobi or .epub). I have a model form set up to create an object:
class NewMediaObjectForm(forms.ModelForm):
class Meta:
model = MediaObject
fields = ('cover_photo', ...)
cover_photo = CloudinaryJsFileField(options={'tags': 'cover_photo'})
Now, I've read this tutorial from Cloudinary and I know that their form looks like this:
class NewMediaObjectForm(forms.ModelForm):
class Meta:
model = MediaObject
fields = ('cover_photo', ...)
cover_photo = CloudinaryJsFileField(options={'tags': 'cover_photo'})
Here's my problem: if I match their level of indention, the generated HTML shows that the input field is getting all of the right Cloudinary stuff attached to it - but the upload itself doesn't work. The page simply refreshes with an error message stating that no image was selected. Importantly, I can see from the generated HTML that the tags I've specified are coming through.
If I use method #1, with my indention, the file uploads to Cloudinary but none of my tags are applied. It also treats everything as an image, giving me a "invalid image file" error when trying to upload anything other than images (such as the ebook files I mentioned earlier).
I want both - how can I get this upload field to work AND get it to respect the options I'm trying to define?
(I do have cloudinary.config called in the appropriate views; I do have cloudinary_includes and cloudinary_js_config in the appropriate templates; I've imported everything and am calling cl_init_js_callbacks on the form in the view.)
One more addition - I am running this on a local machine using manage.py's runserver rather than deploying, if that has any impact on the configuration.
UPDATE:
I found something I was doing wrong. I've fixed it and made things worse.
The necessary jQuery was not being loaded. Now I am loading it, but the upload button simply doesn't function. I press the button, I select the file, the select dialog disappears, and it shows that no file has been selected. However, I can see that the tags are being passed to the generated HTML, so it's a step in the right direction. Any ideas?
Please forgive me. This was a PEBCAK issue; I will leave this visible for anyone else who may make the same mistakes I've made in the future.
Make sure the proper jQuery scripts are being loaded - open the Chrome developer console, Firebug, whatever and double check. Then, make sure they're being loaded after the DOM so that there are elements for the script to attach to.
Cloudinary will expect html/cloudinary_cors.htmlto be accessible in your static directory.
Either I have broken something, or the default behavior for this particular type of ModelField is to simply IMMEDIATELY upload the selected file and continue displaying "No File Chosen." I thought that nothing was happening and was very surprised when I saw 50+ images successfully uploaded.