How to Create website Controller in Odoo 18 | Handle Public and User Authentication — Transcript
Full transcript
- 0:00Hello, welcome to my YouTube channel.
- 0:03So, in this video, we will show you how
- 0:05to create the website controller. Okay.
- 0:08So, like whenever you hit any URL on
- 0:11the website. So, this is your URL. Okay
- 0:15, you know whenever you write any URL
- 0:18here, what page will reload on the
- 0:20website? Like, in this URL, you can see
- 0:23this page. Okay? So basically, similar
- 0:27to this, write the URL here, and see
- 0:31what message will show on your screen,
- 0:34how to create the API, and how you will
- 0:38get the user data from your work data
- 0:41sent on the portal site. Okay, so you
- 0:45have to create the API with the POST
- 0:47method and many other things; we will
- 0:49cover every small thing in this video.
- 0:52Okay, so let's start, without wasting
- 0:56much time. Okay. First, I have already
- 0:58created the module, and this is Odoo 18
- 1:01version, and this is Enterprise. You
- 1:04can also use the Community version. The
- 1:06same module will work on the Community
- 1:07version. Okay. So first, let me show
- 1:11you the module; I am going to my file
- 1:14technical site. Okay. So, this is my
- 1:19custom addons. Here, I have created one
- 1:22module; the name of this module is
- 1:24website_controller, okay. So, in this
- 1:27website_controller module, I created a
- 1:30folder named controllers; in this
- 1:33folder, we have to write the code
- 1:36related to the website, okay. Which
- 1:39code will work on the website portal?
- 1:42Basically, whenever any URL is hit,
- 1:45that code and that file will run, okay.
- 1:48Based on this, inside this, we create
- 1:50an init file; this is the internal init
- 1:52file. After that, creating the main
- 1:54file; the main file is the Python file,
- 1:57okay. So, that file is imported in the
- 2:00init file, okay. After that, I have
- 2:03created an external file; we have to
- 2:06link the controller module in this file
- 2:08. After that, the manifest; in this
- 2:11module, the manifest will tell you
- 2:13about the module. You can write a
- 2:15message according to your requirement
- 2:17and what the version of the module will
- 2:19be, okay. So, I am adding the
- 2:21dependencies for two modules: base and
- 2:24website. Okay. Now, going to the main
- 2:28file. So, let's explain the code to you
- 2:30. So, first, I am importing the http
- 2:33code and second is the http request.
- 2:36Okay? So, this is the first module,
- 2:40okay? My first controller writes a
- 2:43website controller. If you go to the
- 2:45http folder file. So, there you can see
- 2:48one class that is Controller. Okay, in
- 2:51the controller you have to write the
- 2:53URL. Okay, we are now going to extend
- 2:58the functions. Now you can see the
- 3:01function Hello World. First is the
- 3:04public user. In the route, in the
- 3:06route's first parameter we have to pass
- 3:09the URL. Okay, whenever you hit this
- 3:12URL, this message will show on the
- 3:14website page. Okay. After that, write
- 3:18HTTP here, so the type is HTTP. So,
- 3:23whenever you click on the website, that
- 3:26URL will be hit. Okay. Auth, auth means
- 3:29authentication. There are two types:
- 3:31public and user, so here we have public
- 3:33and user. If it is public, if you write
- 3:36here auth is public, then anyone can
- 3:39access this URL and get the data on the
- 3:41page. Okay. And if you write user here,
- 3:45then you have to be a part of the Odoo
- 3:51user. Like if in Odoo you have created
- 3:54three to four users, then only those
- 3:57users can access the URL. Okay. And
- 4:01website equals true, so it means that
- 4:04this URL will be hit on the portal site
- 4:06. Okay. URL website Google. Now let me
- 4:11show you one by one. So, I am creating
- 4:15one folder named Hello World and
- 4:16passing one argument as a keyword, you
- 4:18can pass the value and it. Okay. Now
- 4:22when I am going to, first let's install
- 4:26and upgrade the module. Go to Apps and
- 4:32install website. So, basically I have
- 4:37already installed this module. Okay. I
- 4:40am going to upgrade my name is Singh.
- 4:49So, basically it is that whenever we
- 4:51create a module, we have to install it
- 4:53first, and what we do is that whatever
- 4:55module or controller we have created,
- 4:57we write all the website-related code
- 4:59inside the controller itself. Inside
- 5:02the controller, we extend our own class
- 5:05, which is the controller class. The
- 5:07function is written inside that. What
- 5:08do we pass in the first route? We pass
- 5:10a URL on which our function will work,
- 5:13and where this URL will be hit and what
- 5:16type it will be, we decide that here,
- 5:18whether it will be HTTP, meaning a
- 5:20website URL. And the second is the
- 5:23authentication, meaning anyone can
- 5:25access it. If auth user is written here
- 5:28, then it must be an Odoo user; whoever
- 5:31is an Odoo user can access it,
- 5:34otherwise no one can access that URL.
- 5:37Okay, website equals to true, it means
- 5:40that this URL will hit the Google page.
- 5:43Okay, let's start with Chrome, and let
- 5:47me show you how it works. So I am
- 5:53copying this and going to the form. Now
- 5:58remove this part, paste it here, and
- 6:02click Enter. So here we will print,
- 6:05here we will print Hello World. This is
- 6:08my first controller in Odoo 18, okay?
- 6:12On Enter, you can see this message here
- 6:16, okay? You can design this page with
- 6:20HTML and CSS. So, in the next video I
- 6:23make, we will design our entire website
- 6:26page, how to send data, how to create a
- 6:28form, how to create it, and everything
- 6:31will hit here, okay? We will also see
- 6:34later which page to hit on what. For
- 6:38now, we are just understanding the
- 6:40basic things of how to modify the
- 6:41website controller and how it is used.
- 6:44Okay? So this was our first one. Now,
- 6:47let me do one thing and open this in a
- 6:50private window where I am not logged in
- 6:52. Right? I am not logged in here, and I
- 6:55am accessing it. So, I am able to
- 6:57access it. And if I talk about the
- 7:00second URL. Here I have written user,
- 7:04so I should be logged in already to
- 7:07access it. Otherwise, what will it give
- 7:10me? It will give an error. Let me show
- 7:12you. I simply pasted it and hit enter.
- 7:20So It means it is saying that either
- 7:24you log in, only then you can redirect
- 7:26it. Sometimes this page will give
- 7:29errors. Okay, otherwise you have to log
- 7:32in to the system, then you can access
- 7:35it. And if I use this same URL here,
- 7:38then it will work. Because I am already
- 7:41logged in. I am already logged in in
- 7:43this window. In this window, I am
- 7:46already logged in with the admin user.
- 7:49Okay, now click on the URL, it works.
- 7:53Hello Admin, you are logged in. Okay,
- 7:57but if I do it in an incognito window,
- 8:02it will say that you have to log in to
- 8:04the system first, then you can access
- 8:06the URL. Okay, Now, let's move to the
- 8:15second and third one, JSON API response
- 8:19. So, for JSON API response, at both
- 8:22public and user levels, it's the same
- 8:23thing with these functions. Whenever
- 8:26you need to create an API, like an API
- 8:29for contact creation, importing
- 8:31products, exporting products, or any
- 8:33export according to your requirement,
- 8:36you can create the API in the system.
- 8:39Okay, so as I explained in the first
- 8:42one, pass the URL here, and this is the
- 8:46same thing. So now, whenever you click
- 8:49on it, whenever you pass JSON type data
- 8:51, you have to write "type equals JSON"
- 8:53here. So, the data you are posting from
- 8:57here, that data will come into your
- 8:59function, which will trigger your
- 9:01function in your system; it must be of
- 9:04JSON type only then can we retrieve
- 9:06that data. Okay, authentication is
- 9:08public; anyone can send the data. Okay,
- 9:11and here we have to pass the method,
- 9:13whether you are sending data or
- 9:15retrieving it; if you are sending data
- 9:17then you will use "POST," and if you
- 9:19are retrieving, then you will use the "
- 9:21GET" method here. Okay, so then I
- 9:23created a variable here for HTTP, which
- 9:26I imported, then "http request dot json
- 9:29," meaning the data I am sending there
- 9:32in the JSON file, I am bringing that
- 9:34data here, retrieving it, and then
- 9:37printing it here, so whatever data I
- 9:40send will be printed. Right, currently
- 9:43I am just printing it, but you can
- 9:45create records in the system, like once
- 9:48you have the data, you can create a
- 9:50contact, create a sales order, create a
- 9:52purchase, or create anything else you
- 9:54want to create in the system according
- 9:57to your needs. Basically, this is about
- 10:00getting the data and knowing how to
- 10:02retrieve it. Okay? Then the similar
- 10:07thing for this user is that if you are
- 10:08an Odoo user, only then can you send
- 10:10data and only then can you create
- 10:11something. Otherwise, you cannot. Okay?
- 10:15So, like if I go here So I am going
- 10:27here, let's go somewhere. Go to the
- 10:39Open source I want to show you
- 10:50something. See, so you can see here
- 11:15that name, phone number, email, and
- 11:18subject are there; this is a page
- 11:21created for you to send any message if
- 11:24you want. So here, you can see that I
- 11:27am not logged into this. So I can send
- 11:30data from here. Then whoever handles
- 11:33this website, this page, and this
- 11:35database will receive the data. Then
- 11:38they will contact me to ask what the
- 11:40query is. They will solve my issue.
- 11:41They will revert back to me. Okay? The
- 11:43email that I am sending. The number
- 11:45that I am writing and sending in it. So
- 11:47this is public. If I had logged in,
- 11:49only then I could have raised a ticket.
- 11:52Only then could I have contacted them.
- 11:56Okay? Only then could I have contacted
- 11:58them. If you are part of this website
- 12:01you can contact them. If you are not
- 12:04part of this website, then it means
- 12:07they are using a public user. Okay?
- 12:10Right now I am a public user. If I am
- 12:13logged into the system, if I am logged
- 12:14in. Then, I am an internal user part of
- 12:17this website. Okay, so let's start by
- 12:21going here. So, on this website, if I
- 12:26click on this, a bad request comes up.
- 12:31Like, let me show you, because you can
- 12:35send data via Postman. Okay, method not
- 12:40allowed! It says, method not allowed,
- 12:43because I am not passing website equals
- 12:45true here and also not passing the
- 12:48method equals post here. That's why the
- 12:51error is showing on the website form.
- 12:54So, you have to install Postman. I have
- 12:57already installed it, so you have to
- 13:01install this module, this app, on your
- 13:05system. Once you install this
- 13:07application on your system, you can
- 13:10post the data. Okay, so let me show you
- 13:13. So click on New. As soon as you click
- 13:24on New, you have to click on this. This
- 13:27will be created for you. Then you have
- 13:30to go here. Then go to the Click on New
- 13:35. Once you click on New. Click on HTTP,
- 13:38after that click on HTTP. Once you
- 13:40click on HTTP request, the same page
- 13:43will appear here but empty, okay. You
- 13:46have to paste the URL here that you
- 13:48first have to copy from the website.
- 13:51Going to the website, you have to copy
- 13:55this part with Ctrl + C, or you can
- 13:59copy and paste it here, okay, and paste
- 14:03here, okay. Once I click here, here you
- 14:07can see your cookies and Postman. Some
- 14:11keys required in Postman will
- 14:13automatically come in the header. If
- 14:16you want to add any extra keys, you can
- 14:18add them, okay. In the body section, we
- 14:21have to send the data in a JSON type
- 14:23like a dictionary, okay. So here I am
- 14:25creating one dictionary, and in this
- 14:27dictionary, I will pass my name, city,
- 14:29and mobile number. I am not from Jaipur
- 14:31, okay, and this is not my contact
- 14:34number, please do not send messages,
- 14:37okay. So this is dummy data, and as I
- 14:40click on the send button, the data will
- 14:44show here, okay. Let's click on it, so
- 14:48let me show you the code here. Here you
- 14:54can see the first message is status
- 14:56equals success, second is hello from
- 14:58JSON API, okay, and the third is the
- 15:00received data, what data will come in
- 15:03this request JSON form, okay. So in the
- 15:06body section, set it here to raw and
- 15:08then select JSON. So once I click on
- 15:11that part, the data will be printed
- 15:13here. Okay? If I change it here like M
- 15:19M Del Akash. Okay. So once I update the
- 15:31data and click on send, then that data
- 15:34will update here. Okay, click on this.
- 15:38So here you can see my name is Akash
- 15:40Singh and the city. So Okay, developers
- 15:45can get the data and use it accordingly
- 15:47. Okay, so this is the public user.
- 15:51Right now, I am using the public user.
- 15:54Okay. After that, this user-this is the
- 15:58user type. First, we have to log in to
- 16:02the system. Okay, first we have to log
- 16:06in to Postman, after that I can access
- 16:09it. Okay, I am already logged in. Let's
- 16:13see if it gives an error or not, maybe
- 16:19it will. Okay, I am going to send data.
- 16:26Okay, I am already logged in. Okay, so
- 16:31let's copy and create a new one. Sorry,
- 16:36something Body raw section, so copy the
- 16:45data from here. The message will come
- 16:49here, and change the method to POST.
- 16:53Now click on send. Yeah, I am already
- 16:56logged in to the system. That's because
- 16:59the cookies are saved in the header
- 17:00sections. Cookies are shared, the
- 17:03session ID is saved here. Okay, so that
- 17:07is why the session is logged in. Let me
- 17:12click on it and right now sending the
- 17:19data. Yeah, right. So I want to show
- 17:23this part; whenever you click send data
- 17:27from the user side, this message will
- 17:30come to you: Odoo session expired. Okay
- 17:33, okay. First, you have to log in to
- 17:35the system, otherwise, you cannot post
- 17:38the data. So let's copy and paste it
- 17:46here. I am going to comment out the
- 17:50above part. Okay, so here is the
- 17:53database name, what is your database
- 17:55name, second is the login ID, here you
- 17:58have to enter the login ID and third is
- 18:00the password. You have to pass the data
- 18:04in the same way, and after that, you
- 18:06have to change the URL here. Okay, so
- 18:09the URL will be-The URL will be
- 18:16authentication. This URL, you need this
- 18:21URL, hit this URL. Now change the URL.
- 18:25Now I am changing the URL. So we have
- 18:28to send data to this URL, which means I
- 18:31will log in here. As soon as I log in,
- 18:34it will print some data here showing
- 18:36what I am right now, I am a public user
- 18:39, I mean an internal user, sorry, I am
- 18:41an internal user. You can check here
- 18:44right now that 'is internal' equals
- 18:46true and 'public' equals false. Meaning
- 18:48I am not a public user right now, I am
- 18:50an internal user, I can access anything
- 18:52inside this. Okay, I can post data.
- 18:55Okay, I did this much, commented it,
- 18:58and now I will run the query above,
- 19:02okay? I will copy the URL again and
- 19:07paste it here. Now it will work. Okay,
- 19:13you can see if I want to add something
- 19:16like an address. Okay. Okay, let's
- 19:30click on. So it will print here. So
- 19:34that is why I am showing you four types
- 19:37of methods and four types of URLs here.
- 19:41First is the website and public user,
- 19:44second is the user internal user
- 19:47website, and third is how to send the
- 19:51JSON API, okay, public and fourth is
- 19:54internal. So I showed you four types of
- 19:58URLs. How we can send data from our
- 20:02website in the controller, how to use
- 20:04the POST method, what the
- 20:06authentication user types are, and I
- 20:09also showed the URL types; if you want
- 20:11to send JSON type, it will be JSON,
- 20:14otherwise, it will be HTTP there. Okay,
- 20:18there are many more things, other
- 20:20parameters and other arguments. I will
- 20:22show you in the next videos. So that is
- 20:25all for this video. We will discuss the
- 20:28rest in the next video. I hope this
- 20:31file—I will paste it in my
- 20:33description, you can get the data from
- 20:36there, okay. If you want to take this
- 20:40module, basically it would be better if
- 20:42you write the code yourself. If you
- 20:44write the code on your own, it will be
- 20:47good for you. Because you know every
- 20:50point: why we write the name, why we
- 20:53write the function name, what the URL
- 20:56and type is, and what mistakes you are
- 20:59making, so check it. I have already
- 21:02pasted it in the description of my
- 21:03video. So thank you. If you have any
- 21:06queries, any questions, you can comment
- 21:08them down below. Okay, so thank you.
About this transcript
This page contains the full transcript of How to Create website Controller in Odoo 18 | Handle Public and User Authentication by Odoo Tech , generated from the public captions YouTube serves with the video. The transcript has 2,895 words across 389 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.
What you can do with it
Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to choose a caption track available on the video.
Free YouTube transcript tool
YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, caption language selection, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.