Error like name 'Document' is not defined

Trying to create simple web page, got error like name ‘Document’ is not defined



Is the doctype name “Employee”?
Did you toggle has published on/off before?

This might be due to the class of the doctype being changed to WebsiteGenerator from Document.

If this is a custom doctype, please go into .py file of this doctype and see if the inherited class is WebsiteGenerator or Document.

Try changing the class to Document and see if that works.

Or might just be an import issue?
See if the import Document command is commented out in that .py file.

Hi @nelson_d,

Please add it.

from frappe.model.document import Document

Thank You!

2 Likes

Hi.

If anyone is encountering the same issue and want to enable the generation of routes for documents web views importing the Document class will remove the error but not generate the routes rather replace the Document class with WebsiteGenerator class generated by frappe.

from frappe.website.website_generator import WebsiteGenerator

class YourDocType(WebsiteGenerator):

this fixes the error and generates the routes. Hope this helps.