I have symbol "$" allowed in URL. Every user of my application has a username. I want to show their profiles with website.com/$USERNAME. I want to route /$USERNAME TO /users/profile/USERNAME. I am trying this
when I hard code it like this
$route['$username'] = "user/profile/username";
its working but when i try it like this...
$route['$(:any)'] = "user/profile/$1";
its not working...
Any help/suggestions?
Related
So, i have this problem when im trying to create my "company", when i didnt have user authentication the view worked just fine. Now i've added django allauth, and this screen appears to me:
enter image description here
So i will leave here my model and my view to create the company
Im just a begginner so sry for my bad explanation
enter image description here
enter image description here
The URLS : https://prnt.sc/K-lKvmfuQtvR
It looks like the problem is with the way your url is setup. Do you have a screenshot of the urls.py as well so we can see how you setup your url mapping. (OP added this screenshot: prnt.sc/K-lKvmfuQtvR)
Your companies/<pk>/ endpoint is catching your "create_company" value and storing it as a variable. Try moving your companies/create_company path above your companies/<pk>/ like so
path('companies/', listing_companies),
path('companies/create_company/', company_create),
path('companies/<pk>', retrieve_companies),
path('companies/<pk>/update/', company_update),
path('companies/<pk>/delete/', company_delete),
Alternatively rename companies/create_company/ to create_company/ like so
path('companies/', listing_companies),
path('companies/<pk>', retrieve_companies),
path('create_company/', company_create),
path('companies/<pk>/update/', company_update),
path('companies/<pk>/delete/', company_delete),
The end goal in either case is simply to make sure your paths are not capturing your "create_company" and storing it as that variable that it is passing along to your path's method.
Working on a Django/React app. I have some verification emails links that look like the following:
https://test.example.com/auth/security_questions/f=ru&i=101083&k=7014c315f3056243534741610545c8067d64d747a981de22fe75b78a03d16c92
In dev env this works fine, but now that I am getting it ready for production, it isn't working. When I click on it, it converts it to:
https://test.example.com/auth/security_questions/f%3Dru&i%3D101083&k%3D7014c315f3056243534741610545c8067d64d747a981de22fe75b78a03d16c92/
This prevents react-router-dom from matching the correct URL, so a portion of the web application does not load properly.
The link is constructed using the following.
link = '%s/auth/security_questions/f=%s&i=%s&k=%s' % \
('https://test.example.com', 'ru', user.id, user.key)
Also, here is the url() that is catching the route:
url(r'^(?:.*)/$', TemplateView.as_view(template_name='index.html')),
These variables are supposed to be query parameters in a GET request. When you construct the link, you'll need to have a question mark in there somewhere separating the URL from the query string:
https://test.example.com/auth/security_questions/?f=ru&i=101083&k=7014c315...
^
|___ here
The conversion of = to url-encoded %3D etc is correct, and equivalent. Sometimes variables are part of the URL directly, but webapps don't use &-separated key/value pairs in that case.
Using play framework, I'm trying to match a route using a regular expression.
What I wanted is to use one action that maps all this urls:
mydomain.com/my-post-title-123
mydomain.com/another-post-title-124
mydomain.com/a-third-post-title-125
get this "123, 124 and 125" from the end of the url so the controller can use it. Basically ignore whatever post tile comes in and only use the number at the end.
I have the following on my routes.conf
GET /$postId<\d$> controllers.Posts.viewPost(postId: Int)
But I get the error page "Action not found"
You are missing the url prefix and "+" in the regex in the routes definition. Here is my route configuration and it works fine
#Regex test
GET /$prefix<.*>$postId<\d+$> controllers.Application.viewPost(prefix:String,postId: Int)
Controllers.Application.viewPost
def viewPost(prefix:String,postId:Int) = Action{
Ok("the post id is: "+postId+" the prefix is:"+prefix)
}
and the output will be
the post id is: 123 the prefix is "whatever/prefix/you/give"
** tested, it works.
Route are defined as
$route['hotels/([a-z]+)/(:any)'] = "hotels/city/$1/$2";
$route['hotels/placename/fivestar'] = "hotels/placename/star/fivestar";
I want to execute the city action in hotels controller when some one type url like
http://website.com/hotels/myspecificcity/fivestar
the above first route is not working. it always load 2nd route . can some one please guide me
i don't want to remove 2nd route though as i will using for other purposes
Thanks
I'd like to send any route that doesn't match an admin route, to my "event" controller. This seems to be a fairly common requirement and a cursory search throws up all sorts of similar questions.
The solution, as I understand, seems to be using a negative lookahead in the regex. So my attempt looks like this:
$route['(?!admin).*'] = "event";
..which works. Well, sort of. It does send any non-admin request to my "event" controller, but I need it to pass the actual string that was matched: so /my-new-event/ is routed to /event/my-new-event/
I tried:
$route['(?!admin).*'] = "event/$0";
$route['(?!admin).*'] = "event/$1";
$route['(?!admin)(.*)'] = "event/$0";
$route['(?!admin)(.*)'] = "event/$1";
... and a few other increasingly random and desperate permutations. All result in a 404 page.
What's the correct syntax for passing the matched string to the controller?
Thanks :)
I don't think you can do "negative routing".
But as routes do have an order : "routes will run in the order they are defined. Higher routes will always take precedence over lower ones." I would do my admin one first then anything else.
If I suppose your admin path is looking like "/admin/..." I would suggest :
$route['admin/(:any)'] = "admincontroller/$1";
$route['(:any)'] = "event/$1";