I recently discovered Django Admin's VIEW ON SITE function, which is pretty cool. I defined get_absolute_url in my model:
def get_absolute_url(self):
return reverse('product-detail', kwargs={'slug': self.slug})
When I hover the link in the admin, I see this URL: http://localhost:8000/adminr/10/4/ and when I click it, it takes me to here (after redirect?): http//localhost:8000/product/<name> (note the missing colon in the URL).
I can define view_on_site in my ProductAdmin and get things to work:
def view_on_site(self, obj):
return reverse('product-detail', kwargs={'slug': obj.slug})
Assuming this just uses the "site" I've defined in the admin already (for domain), which is http://localhost:8000. What am I missing? Is this a bug or am I doing something wrong?
I posted on the Django forum and got the answer:
https://forum.djangoproject.com/t/admin-sites-view-on-site-url-incorrect/4602
Turns out I was specifying the wrong thing in the Domain Name field in the Django admin. I had the URL scheme included like this: http://localhost:8000
And the field actually wants this: localhost:8000
The validation doesn't catch this, so this is why I never noticed it before.
Related
I have the following ruby code in a model:
if privacy_policy_link.match(/#{domain}($|\/$)/)
errors.add(:privacy_policy_link, 'Link to a specific privacy policy page on your site instead of your homepage.')
end
This worked until a user tried to save a privacy policy link that looked like this:
https://example.com/about-me/privacy-policy-for-example-com/
The goal is that I don't want them linking to their base homepage (example.com or www.example.com etc) for this privacy policy link (for some random, complicated reasons I won't go into). The link provided above should pass the matcher (meaning that because they are linking to a separate page on their site, it shouldn't be considered a match and they shouldn't see any errors when saving the form) - but because they reference their base domain in second half of the url, it comes up as a match.
I cannot, for the life of me, figure out how the correct regex on rubular to get this url to pass the matching algorithm. And of course I cannot just ask the user to rename their privacy policy link to remove the "com" from it at the end - because this: https://example.com/about-me/privacy-policy-for-example would pass. :)
I would be incredibly grateful for any assistance that could help me understand how to solve this problem!
Rubular link: http://rubular.com/r/G5OmYfzi6t
Your issue is the . character is any character so it matched the - in example-com.
If you chain it to the beginning of the line it will match correctly without trying to escape the . in the domain.
if privacy_policy_link.match(%r{^(http[s]?://|)(www.)?#{domain}($|/$)})
I am using orchard 1.9 and I am building a service in which I need to get current URL.
I have OrchardServices and from that I can get the URL like so:
_orchardServices.WorkContext.HttpContext.Request.Url.AbsolutePath;
This works like a charm for pages/routes that I have created but when I go to the Login or register page (/Users/Account/LogOn) the absolute URL is / and I can't find anyway to get the URL or at least any indication that I am in the LogOn or Register.
Anyone knows how I could get the full url?
If I understand what your're asking, you could use the ItemAdminLink from the ContentItemExtension class.
You will need to add references to Orchard.ContentManagement, Orchard.Mvc.Html and Orchard.Utility.Extensions, but then you will have access to the #Html and #Url helpers.
From there you will have the ability to get the link to the item using:
#Html.ItemDisplayLink((ContentItem)Model.ContentItem)
The link to the item with the Url as the title using: #Url.ItemDisplayUrl((ContentItem)Model.ContentItem)
And you should get the same for the admin area by using these:
#Html.ItemAdminLink((ContentItem)Model.ContentItem)
#Url.ItemAdminUrl((ContentItem)Model.ContentItem)
They will give you relative paths, e.g. '/blog/blog-post-1', but it sounds like you've already got a partial solution for that sorted, so it would be a matter of combining the two.
Although I'm sure there are (much) better ways of doing it, you could get the absolute URL using:
String.Format("{0}{1}", WorkContext.CurrentSite.BaseUrl, yourRelativeURL);
...but if anyone has a more elegent way of doing it then post a comment below.
Hope that helps someone.
kind of finding it difficult to wrap my head around this. For those who have used the Symfony admin generator extensively, for each module based of a backend module, there is an edit page for all the records. Typically this can be accessed like this:
module/primarykey/edit. (assume questions/1/edit)
which is strange because typically the primary key would be passed in as a URI parameter like:
questions/edit/1. Anyways, that maybe irrelevant. What is important is how do I manage to generate a link_to for the above URI. I am linking the editSuccess page through an external page which does not belong to the UI. The syntax I use is
link_to('Edit','questions/'.$primary_key.'/edit') // (where $primary_key = 1 as in this case)
However that auto modifies itself to :
/backend_dev.php/questions/1/action note the action instead of edit
No such action exists and it returns a 404 error stating that questions/action does not exist
To summarize, How do you link to an admin page that renders specifically for a record?
The url_for (and thus the link_to) helpers deal with internal urls, not external ones. The syntax is module/action?parameters. In your case this would be question/edit?id=$primarykey (assuming the action looks for the id parameter).
If you give a name to your route, that makes generating the link faster (hashtable lookup vs. linear search):
echo url_for("#question_edit?id=$primary_key");
If you set up your route as an sfDoctrineRoute, it gets even simpler:
echo url_for("question_edit", $question);
note how you need not pass the id, but the question object - the route class will fetch all neccessary parameters.
i am using symfony 1.4.11; use_helper('Url').
On using link_to('new',course/course/type/new),
the url it show is ../backend_dev/backend_dev/Course/course/type/new
instead of
../backend_dev/Course/course/type/new.
Same issue exist for form_tag also.
Edit
Above issue was solved.By setting no_script_name: true at config and clearing cache.
But image_tag(),use_stylesheet() and use_javascript() gives path as for example
use_javascript('jquery-1.6.1.min.js')
==>../web/backend_dev/js/jquery-1.6.1.min.js
instead of
use_javascript('jquery-1.6.1.min.js') ==>../web/js/jquery-1.6.1.min.js
Any help appreciated.
Hard to say without your full routing.yml but the one thing i see is that your internal_uri should be expressed as an abs url with a query string like:
link_to('new','/Course/course?type=new');
Note the forward slash at the beginning. Also the module name should be the real module name, not the routed one so if the maodule is /apps/backend/modules/Course then the module in the internal URI should be Course not course same with the action name.
If the route is named then you should use one of the following:
link_to('new','#routename?type=new');
OR
link_to('new','routename', array('type'=>'new'));
Please help I want to use first URI segment into my CodeIgniter website.
Like when I open these url they opens my profile:
http://www.facebook.com/buddyforever
or
http://www.myspace.com/zarpio
How can I do this with CodeIgniter? I checked _remap function but first coming controller how to hide controller?
You can do this using the URL routing of codeigniter...
If you want your URL to be http://www.mydomain.com/zarpio and you want it to refer to your_controller, then do the following.
/config/routes.php
$route['(.*)'] = "your_controller/$1"; // Now, `zarpio` will be passed to `your_controller`
You can access it in your controller like this...
$my_name = $this->uri->rsegment(2);
However I do not suggest this way of configuring URLs. A better way would be...
$route['users/(.*)'] = "your_controller/$1";
This way, you're just renaming your controller name your_controller to users.
If you want to access profile of a user, you can do it like this...
$route['users/profile/(.*)'] = "another_controller/method/$1";
$route['users/(.*)'] = "your_controller/$1";
Consider the order of routing. Since you wrote users/(.*) in your route, it will match users/zarpio as well as users/profile/zarpio, and route both of them to your_controller/$1, which in the case of profile will give you a 404 page not found error. That is why you need to write users/profile/(.*) before users/(.*) in your routing configuration.
More information in codeigniter URI class documentation