Flask route to a variable url - html

I want to be able to route to a specific user's profile using flask as a web server but the user's profile name will be different so how would implement this?

The variable is surrounded by square brackets in the URL and passed to the view function as a regular parameter.
Assuming you have a template called profile.html and want to pass user data to that template from function getUser, your route would look like this:
#app.route('/profile/<username>')
def profile(username):
return render_template('profile.html', user = getUser(username))

Related

How to read UTM tags and redirect url in react

I have an URL with UTM tags as below. When a user clicks/ hits the below URL(source), I would like to read UTM tags and redirect to another url(target).
Does anyone have a documentation link to read UTM tags and redirect the url in react?
Example:
Source
https://www.CustomDomain.com/?utm_source=linkedin&utm_medium=email&utm_campaign=sale&utm_id=123&utm_term=job&utm_content=ad
Target
https://www.CustomDomain.com/dashbord
With the latest react-router-dom *v6*, you can use a new hook named useSearchParams. Use it to get query params and you can then store them into localStorage,:
const [searchParams, setSearchParams] = useSearchParams();
searchParams.get("utm_source"); // similar for the rest of query params
With React router v4, You need to use this.props.location.search for generic or this.props.location (with useLocation) for functional components and parse the query parameters either by yourself or using a package

Angular 8 ngx-translate load translation JSON file from URL

I have a problem with ngx-translate. I'm making a component where I would like to pass an URL with JSON file with translations. For now, all translations are gathered from /assets/i18n/ directory. My goal is to not place any translations to this folder, but to provide my component with #Input decorator and to pass URL to this input with the whole translation file.
This is what I managed to achieve right now:
In my app.module.ts file I have this function:
export function HttpLoaderFactory(http: HttpClient) {
return new TranslateHttpLoader(http, 'http://127.0.0.1:8080/', '.json');
}
and this is working fine. I have passed my test URL as second parameter to TranslateHttpLoader function. But in my case, I don't want to hardcode this second parameter in my app.module.ts. I need to pass URL for this parameter. In case I remove this parameter from this function, my translations are not working at all. I have tried with passing this through a service, but everytime I receive an undefined property for this URL.
In my main component I'm setting this in constructor:
translate.getTranslation('http://127.0.0.1:8080/en.json');
Can anyone help with setting this? I could not find any solution for that.

Search query for JSON data by url

I'm using the following url for my JSON data.
myapp/laravelRoute/jsondata
when entering this in address bar, following JSON array will be displayed
[{"A":"B"},{"B":1},{"C","http"}]
But, when I enter the url as,
myapp/laravelRoute/jsondata?search=B
it shows the entire array instead showing the search result. How I do this correctly?
After doing the code view I found that the array route is configured for a default route in Laravel Routes. So, in any case that open a path except mentioned ones in routes will redirect to the default path.

MEAN.js $http.get() return index html content instead of json file

I'm doing a web app based on original MEAN.js framework. When I want to request local json test file using $http.get() method in my AngularJS file, it returned my index html content.Is it a routing problem? I didnot change the original mean.js routing code(https://github.com/meanjs/mean), just added a $http.get() method in home.client.controller.js file. Can anyone help me with this? Thanks!
That is most likely happening, because you didn't define an endpoint for that particular GET request in your app.
Everytime you make a request to your server (for example a GET request to /my-request) nodejs/express are configured in MEAN.js so that your server will try to find the endpoint for that request, if it does not find any, that request will be handled by this particular code block (specified in /modules/core/server/routes/core.server.routes.js):
// Define application route
app.route('/*').get(core.renderIndex);
Which will basically render the index view.
I'm not sure if you're using a custom module or not, eitherway, if you want that request to be handled in a different way in MEAN.js, you can specify your endpoint in your custom module routes file (or in core.server.controller.js) like so:
// Define application route
app.route('/my-request').get(core.sendMyJSON);
Be careful, because this route must be placed before the one I mentioned earlier, otherwise your request will still be handled the same way and the index view will be rendered and served again.
Then you will have to create the controller that should be called to handle that request:
exports.sendMyJSON = function (req, res) {
// logic to serve the JSON file
};
This way you should be able to get it done with a few adjustments.
Side note:
I'm not entirely sure but I think if you place your JSON file in the public directory of your app you should be able to directly access it without the need for the extra logic.

How to store action result and pass as http header

Currently I'm trying to create a simple login form with Microsoft PowerApps.
I have a login action (Web API2) that is called:
SampleAPI.AuthLogin({UserName:UserNameTextBox.Text, Password:PasswordTextBox.Text})
This is working great. The Login method is returning a json web token which should be passed in all following requests. Is this possible?
Futhermore, when clicking on the Login button, a new screen should appear. (Using Navigate).
So how can I set the result of AuthLogin as the Authentication Header in all following http requests?
Thank you very much!
Yes, this is possible. I'm not sure what aspect of what you are trying to do is causing you grief.
I'm going to guess it is holding on to the json web token that is returned. I'm guessing you would like the equivalent of a global variable to hold this value? PowerApps does not have global variables, but it does have global collections. Use the Collect function to store the value in a collection that you can then access from anywhere in the app. You can view collections in your app with the File menu.
If you don't need a global variable, as a variable scoped to the screen will suffice, then you can use a context variable instead.