finding a way to replace images to proper url's - replace

i am getting contents from a website: The images are coming as: /images/abc.gif, so what it is doing is it is attaching my website url to it and giving me network error: here is an example of this
"NetworkError: 404 Not Found - https://devl.example.com/segment/Images/HeadCont.gif"
HeadCont.gif
"NetworkError: 404 Not Found - https://devl.example.com/segment/images/NewDetails.gif"
NewDetails.gif
"NetworkError: 404 Not Found - https://devl.example.com/segment/Images/HeadSurr.gif"
i am using this code for replace of images
<cfset lnk = replace(lnk,'"/images/sym_s_up.gif"','"http://thewebsite.com/images/sym_s_up.gif"','ALL')>
but the above is doing for the image i specify, how can i write some kind of single code where it searches all the /images and replace them with the url irrespective of the image name i have to specify

Remove the actual image name and search for a consistent string
<cfset lnk = replace(lnk,'/images/','http://thewebsite.com/images/','ALL')>
You could also take the approach of replacing something like <img src="/images and replacing that with your full url.

Related

Django url having %20 issues

One of my urls in url.py goes like this is like this
path('<str:subject>/<str:agglevel>/<str:cust_cd>/',views.Customer.as_view())
cust_cd takes value from UI. cust_cd is basically customer name which is a string value.
Url works fine for single words for cust_cd. Ex:Google,Gmail etc. But when I give words with spaces like Ex:You tube I get 404 error. It says you%20tube not found. Am not able to figure out how to configure url so that it accepts space characters.
in your urls.py file
instead of
<str:cust_cd>
try this
<slug:cust_cd>
for more information check out this link: https://docs.djangoproject.com/en/3.0/topics/http/urls/#path-converters

Moved legacy classic asp web site to django app but having trouble with django URL redirect app - old URLs with parameters get 500 error

I moved a 20 year old classic asp web site to a django app recently. Google Search Console is showing 500 errors for tons of very old URLS with parameters like /somefile.asp?ID=1234&name=some-name. Most of these URLS I don't even care about - they are really old but would rather they result in 404 than 500. Some do relate to newer content and in theory I could redirect to new django pages but when I try to redirect them using the django redirect app, the site shows 500 errors - like the ? either stops the pages from ever getting to the redirect middleware or the redirect app doesn't like the "?". How can I redirect these urls so I don't get 500 errors? Is there a way in a view to say:
if the full url path is x
redirect to full url path y
I have looked all over stack overflow and elsewhere and can't find this exact problem or a way to write a view like this. I did try the solution here (exactly) because it seems closest to my issue, but it did not work for me for this exact problem: Django's redirects app doesn't work with URL parameters
An example would be /profiles/?adid=134&v=857
The error with debug true is:
DoesNotExist at /profiles/
BusinessCategory matching query does not exist....
So it is trying to match this URL:
path('<slug:slug>/', views.view_category_list, name='view_category_list'),
before it ever gets to the /?
Relevant view code:
def view_category_list(request, slug):
try:
category_detail = BusinessCategory.objects.get(slug=slug)
except BusinessCategory.DoesNotExist:
category_detail = None
if category_detail:
--code here is all working fine so removed it to get to the issue--
else:
raise Http404
I hoped raising the 404 would call up the redirect app to do its job at redirecting to a specific url but it doesn't - it just shows the custom 404 when debug is False. Anyway, the 404 is better than the 500 for SEO purposes but I still would prefer being able to actually redirect some of the URLs to relevant content.

Remove last part of URL with regex

I have lot of URL links that looks like:
https://www.example.com/category/product_name?product_rewrite=product_name
I am trying to redirect them to:
https://www.example.com/category/product_name
I have a module in Prestashop where I can put regex for redirect old to new URL.
I am trying with:
OLD URL: https://www.example.com/(.)\?product_rewrite=(.)
New URL: https://www.exampe.com/(.*)\
Unfortunately above is not working and can not find why - because module is not working properly or because I am giving wrong data.

Trouble with redirecting to an absolute_uri

I'm attempting to redirect to a full url
current url is an absolute_uri
currenturl = request.GET.get('currenturl') #lets say this resolves to http://www.google.com/
return redirect(currenturl)
This sends me to an 404 error page as it's trying to resolve the following url
http://localhost:8000/accounts/profile/calendar/delete/15/'http://www.google.com/'
I was passing the absolute uri in the template into the currenturl with single quotes around it. I had to remove the single quotes.

404 on a simple template view - strange

I have a django app set up consisting of ListViews, TemplateViews etc..
So, I just added a small templateview to it like so:
#views.py
class TermsTemplateView(TemplateView):
template_name = "terms.html"
#urls.py
url(r'^terms/$', TermsTemplateView.as_view(), name='terms'),
and in terms.html, I am using for linking:
Terms & Conditions
For some strange reason, I keep getting 404 on localhost/terms as follows:
404: No <model_name> found matching the query
I am baffled why this is happening all of a sudden. I have the same set up for "about", "thanks", "contact" pages, and they seem to display it with no problems.
..and the worst part is, if I modify the urls.py like so:
url(r'^/terms/$', TermsTemplateView.as_view(), name='terms'),
and then go to http://127.0.0.1:8000//terms/ - the page seems to be there.. I am surprised why this is so :(
Any help would enlighten me!
The / at the end is the culprit of your problems. localhost/terms doesn't match '^terms/$' regular expression, localhost/terms/ does.
You can make / at the end optional by using ?:
url(r'^terms/?$', TermsTemplateView.as_view(), name='terms'),
UPD: Note that there is a better solution to the problem, APPEND_SLASH:
When set to True, if the request URL does not match any of the
patterns in the URLconf and it doesn’t end in a slash, an HTTP
redirect is issued to the same URL with a slash appended.
Also see:
Why would you need a slash at the end of a URL?
django - url with automatic slash adding
Append Slashes to URLs in Django