Introduction: What Are Generators in Frappe?
In Frappe Framework v15, Generators are a website feature that automatically create dynamic pages from database records. Instead of manually building individual pages, generators use DocType data to generate multiple URLs using a single template.
This mechanism is widely used in portals, blogs, product catalogs, and customer dashboards.
What Is a Generator in Frappe?
Answer:
A Generator is a website routing system that maps DocType records to dynamic web pages using predefined templates.
Each record becomes an accessible URL without requiring separate page creation.
Example:
/blog/my-first-post
/customer/john-doe
These URLs are generated automatically from stored records.
How Generators Work in Frappe v15
Generators operate through three main components:
- Route Field – Stores the URL path
- Web Template – Defines layout and rendering
- Context Function – Supplies data to the page
When a visitor opens a URL, Frappe:
- Finds the matching record
- Loads its template
- Renders content dynamically
This enables scalable content delivery.
Core Components of a Generator
1. Route Field
Each generated page uses a route stored in a DocType field.
Example:
route = "blog/my-post"
This determines the public URL.
2. Web Template
The Web Template controls page design and layout.
It defines:
- HTML structure
- Jinja variables
- Styling logic
Templates are reused across all generated pages.
3. Context Function
The context function supplies dynamic data.
It prepares:
- Document values
- User permissions
- Related records
- Metadata
This ensures pages load accurate information.
Creating a Generator in Frappe v15
Step-by-Step Setup
- Create or select a DocType
- Add a route field
- Enable Has Web View
- Assign a Web Template
- Configure permissions
- Save and publish
After setup, each document automatically becomes a web page.
Enabling Web View for DocTypes
To activate generators:
- Open DocType
- Enable Has Web View
- Set Route Field
- Assign Template
This allows Frappe to expose records on the website.
URL Routing Mechanism
Frappe resolves generator URLs by:
- Matching route pattern
- Finding related DocType
- Fetching record
- Loading template
- Rendering response
This process is optimized for performance in v15.
Using Context in Generator Pages
Context Structure
Context is passed as a Python dictionary.
Typical elements:
- doc – Current document
- user – Logged-in user
- meta – SEO metadata
- children – Linked records
Context ensures data availability in templates.
Permissions and Access Control
Generators follow strict permission rules:
- DocType read permissions
- Role-based access
- Portal user restrictions
- Private document handling
Unauthorized users cannot access protected pages.
Common Use Cases
Generators are used for:
- Blog systems
- Knowledge bases
- Customer portals
- Product catalogs
- Service listings
They reduce manual page management.
Real-World Example: Blog Generator
Example implementation:
- DocType: Blog Post
- Route: blog/{{ name }}
- Template: Blog Template
- Context: Post content
Each blog entry becomes:
/blog/post-name
Automatically.
Best Practices for Generators
- Use SEO-friendly routes
- Avoid duplicate URLs
- Validate route uniqueness
- Cache frequently accessed pages
- Optimize templates
These practices improve performance and indexing.
Advanced Generator Customization
Custom Routing Logic
Developers can override routing using:
- Hooks
- Controller methods
- Custom context processors
This enables complex URL structures.
Dynamic Metadata
Generators can define:
- Meta titles
- Descriptions
- Open Graph tags
Using context variables.
This enhances search visibility.
Integration with Portal Pages
Generators work with:
- Portal Roles
- Web Forms
- User dashboards
- Account pages
This allows building complete self-service portals.
Troubleshooting Generator Issues
Page Not Found (404)
Check:
- Route field value
- Has Web View enabled
- Document published status
Template Not Loading
Verify:
- Template name
- File path
- Jinja syntax
Permission Denied
Review:
- DocType roles
- Website permission rules
- Portal role mapping
Technical Scope
| Attribute | Value |
| Framework | Frappe v15 |
| Module | Website |
| Feature Type | Dynamic Routing |
| Applies To | ERPNext + Custom Apps |
Industry Relevance
Generators are essential for:
- SaaS platforms
- ERP portals
- Documentation sites
- B2B catalogs
- Membership systems
They support scalable digital operations.
Target Audience Tags
- Frappe Developers
- ERPNext Consultants
- Portal Architects
- Website Engineers
- System Integrators
Cross-References
Official Docs
https://docs.frappe.io/framework/user/en/guides/portal-development/generators
Portal Pages
https://docs.frappe.io/framework/user/en/guides/portal-development
Frappe v15 Source
https://github.com/frappe/frappe/tree/version-15
Conclusion
Generators in Frappe Framework v15 provide a powerful, scalable way to publish dynamic content directly from database records. By combining routes, templates, and context, they eliminate manual page creation and enable secure, SEO-friendly portals.
When implemented correctly, generators become the foundation of modern Frappe-based websites.