Odoo-v8技术咨询:如何实现未登录状态下单独访问首页?
Hey there! Let’s walk through exactly how to make your Odoo v8 homepage accessible without requiring users to log in—whether you want to unlock the existing system homepage or build a completely custom public landing page.
If you want your current Odoo dashboard/homepage to be viewable by unauthenticated users, follow these steps:
Adjust the homepage route's authentication setting
Odoo v8’s default homepage route (/web) is restricted to logged-in users. To change this, navigate to thewebmodule’s controllers:web/controllers/main.py. Find theindexmethod and modify theauthparameter in the@http.routedecorator from"user"to"public"(allows access to the Public user group) or"none"(completely unrestricted access). For example:@http.route('/web', type='http', auth="public") def index(self, s_action=None, **kw): # Existing method code hereGrant necessary permissions to the Public group
Go toSettings > Users > Groups, find the Public group, and add read access to models used by the homepage—typicallyir.ui.menu(for menu items) andir.ui.view(for page views). This ensures unauthenticated users can load the page’s components without permission errors.Ensure homepage views are visible to Public users
Edit the main homepage view (usually part of theweb_clientmodule) and set its access rights to allow the Public group to view it. You can do this via the view’s edit interface underSettings > Technical > User Interface > Views.
If you want a dedicated, brand-new page to serve as your public homepage, here’s how to build it:
Create a custom module
Start by making a new module (e.g.,custom_public_homepage) with the standard Odoo module structure:custom_public_homepage/ ├── __init__.py ├── __openerp__.py ├── controllers/ │ └── main.py └── views/ └── templates.xmlWrite the controller for your public route
Incontrollers/main.py, define a route withauth='public'to handle unauthenticated requests. You can map it to the root path (/) so it loads when users visit your domain:from openerp import http from openerp.http import request class PublicHomepageController(http.Controller): @http.route('/', type='http', auth='public', website=True) def public_homepage(self, **kw): # Add any dynamic content logic here (e.g., fetch public products) return request.render('custom_public_homepage.public_home_template', { 'greeting': 'Welcome to Our Public Portal!', })Build the QWeb template
Inviews/templates.xml, create a QWeb template for your homepage. You can inherit Odoo’swebsite.layoutto keep consistent styling:<openerp> <data> <template id="public_home_template" name="Custom Public Homepage"> <t t-call="website.layout"> <div class="container mt-5"> <h1 class="text-center"><t t-esc="greeting"/></h1> <p class="text-center">This page is fully accessible without logging in.</p> <!-- Add more content here (images, links, etc.) --> </div> </t> </template> </data> </openerp>Install and configure the module
Install your new module via Odoo’s app store or by updating the module list. Once installed, the root path (/) will now load your custom public homepage. If you still need the original/webroute for logged-in users, leave it unchanged—it’ll still work for authenticated users.Secure your setup
Avoid giving the Public group unnecessary permissions to sensitive models (likeres.partneroraccount.move) to prevent unauthorized access to private data.
Quick Notes
- Always test changes by logging out and accessing the page as an anonymous user to confirm it works.
- Using
auth="public"is safer than"none"because it ties access to the Public user group, letting you refine permissions later if needed.
内容的提问来源于stack exchange,提问作者Jesus

