Frappe web page with params

hello

I have one app having few doctypes. Also, in same app, I have created one web page that does not require login. So, I can access it from http://localhost:8080/home.

Now, I want home page with query string params e.g. http://localhost:8080/home/aaa OR http://localhost:8080/home/bbb where aaa & bbb are query string params. So, how can I specify the same and where? urls with params also land to home page only and then want to perform some action based on params.

Hello @grh if your url is like this http://localhost:8080/home?aaa=something&bbb=something_else
then in your .py file add like this–
def get_context(context):
query_params = frappe.request.environ.get(‘QUERY_STRING’)

Varialble query_params has everything you need now.
Please reply if it works

Or you can just use this-
frappe.request.args

1 Like

“aaa” and “bbb” are query string params value. there will be only one param. also, issue is that I want nice urls, so http://localhost:8080/home/aaa should go to home page only. But , for now it is considering home/aaa as another page, and so gives “page missing or moved” error.

Hello all,

Can we have User friendly url and redirection rules in frappe? The way we do it in IIS web site, what is the option in frappe?

i.e. my het request for /home?key=455 should looks like /home/455/ and go to home page only.

Can anyone help into this?
Actually I want to make get request with parameter with nice url like /home/value1. i.e. it should map to home?p1=value1 where param 1 is value for parameter p1. I want it should land to home page only and javascript on page will extract params and do further as per my need.

But just now /home/value1 tries to find page “value1” considering home as directory. And so gives page is missing error.

I am trying to solve this from many days.

I have app with doctypes and one web page named home. I need this on web page. Then where to write this method?

Where did you create that home page? In www folder?

No created using web page inside website module

You can use frappe.get_route()[1] to extract the value aaa or bbb or whatever value you pass there.

In my use case, I wanted to render a custom page and fetch the data for the specific ID passed in.

Here are my steps (Frappe v13, ERPNext v13, with a custom app):

  1. Create a custom page (Go to Desk, search for Page List, Create New Page)

  2. Edit the JS within your page directory. Here is a snippet of mine:

     frappe.pages['item-detail'].refresh = function (wrapper) {
     	new ItemIDDetail(wrapper);
     }
    
    let get_item_by_id = async (item_id) => {
     console.log(item_id);
         // Call API here, or do whatever you need to do
     
    }
    
    ItemIDDetail = Class.extend({
     init: function (wrapper) {
     	this.page = frappe.ui.make_app_page({
     		parent: wrapper,
     		title: 'Item ID Detail',
     		single_column: true
     	});
     	this.make();
     },
    
     make: async function () {
     	let item_id = frappe.get_route()[1]; //If you call /app/item-id-detail/34223, item_id will be 34223
     	let item = await get_item_by_id(item_id);
                 this.item = item;  // Passing this as context to the rendered template
     	$(frappe.render_template('item-id-detail', this)).appendTo(this.page.main); //Template to render to
     }
    });
    
  3. Create a HTML file inside your page dir, and name it item-id-detail.html
    This is what will be rendered.

  4. Proceed to render the context data within your item-id-detail.html file

<p>{{item.name}}</p>

1 Like