Website Generator error

I wanted to change the default view of current html file so created a html file in doctype/generator/myhtmlfile.html

and and i added this line to .py file in schools/doctype/program/program.py

from frappe.website.website_generator import WebsiteGenerator

class Program(WebsiteGenerator):
website = frappe._dict(
template = “templates/generators/program.html”
)

and i added “Program” to website_generators in hooks.py file

and then i navigated to desk of erpnext->school->program->new->save

i am getting the error

Did not save
Server Error: Please check your server logs or contact tech support.

Traceback (most recent call last):
File “/home/shahid/meeting/frappe-bench/apps/frappe/frappe/desk/form/save.py”, line 22, in savedocs
doc.save()
File “/home/shahid/meeting/frappe-bench/apps/frappe/frappe/model/document.py”, line 223, in save
return self._save(*args, **kwargs)
File “/home/shahid/meeting/frappe-bench/apps/frappe/frappe/model/document.py”, line 242, in save
self.insert()
File “/home/shahid/meeting/frappe-bench/apps/frappe/frappe/model/document.py”, line 184, in insert
self.set_new_name()
File “/home/shahid/meeting/frappe-bench/apps/frappe/frappe/model/document.py”, line 322, in set_new_name
set_new_name(self)
File “/home/shahid/meeting/frappe-bench/apps/frappe/frappe/model/naming.py”, line 38, in set_new_name
doc.run_method(“autoname”)
File “/home/shahid/meeting/frappe-bench/apps/frappe/frappe/model/document.py”, line 651, in run_method
out = Document.hook(fn)(self, *args, **kwargs)
File “/home/shahid/meeting/frappe-bench/apps/frappe/frappe/model/document.py”, line 858, in composer
return composed(self, method, *args, **kwargs)
File “/home/shahid/meeting/frappe-bench/apps/frappe/frappe/model/document.py”, line 841, in runner
add_to_return_value(self, fn(self, *args, **kwargs))
File “/home/shahid/meeting/frappe-bench/apps/frappe/frappe/model/document.py”, line 645, in
fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
File “/home/shahid/meeting/frappe-bench/apps/frappe/frappe/website/website_generator.py”, line 25, in autoname
self.name = self.scrub(self.get(self.website.page_title_field or “title”))
File “/home/shahid/meeting/frappe-bench/apps/frappe/frappe/website/website_generator.py”, line 52, in scrub
return cleanup_page_name(text).replace('
', ‘-’)
AttributeError: ‘NoneType’ object has no attribute ‘replace’

Traceback (most recent call last):
File “/home/shahid/meeting/frappe-bench/apps/frappe/frappe/app.py”, line 55, in application
response = frappe.handler.handle()
File “/home/shahid/meeting/frappe-bench/apps/frappe/frappe/handler.py”, line 19, in handle
execute_cmd(cmd)
File “/home/shahid/meeting/frappe-bench/apps/frappe/frappe/handler.py”, line 40, in execute_cmd
ret = frappe.call(method, **frappe.form_dict)
File “/home/shahid/meeting/frappe-bench/apps/frappe/frappe/init.py”, line 898, in call
return fn(*args, **newargs)
File “/home/shahid/meeting/frappe-bench/apps/frappe/frappe/desk/form/save.py”, line 22, in savedocs
doc.save()
File “/home/shahid/meeting/frappe-bench/apps/frappe/frappe/model/document.py”, line 223, in save
return self._save(*args, **kwargs)
File “/home/shahid/meeting/frappe-bench/apps/frappe/frappe/model/document.py”, line 242, in save
self.insert()
File “/home/shahid/meeting/frappe-bench/apps/frappe/frappe/model/document.py”, line 184, in insert
self.set_new_name()
File “/home/shahid/meeting/frappe-bench/apps/frappe/frappe/model/document.py”, line 322, in set_new_name
set_new_name(self)
File “/home/shahid/meeting/frappe-bench/apps/frappe/frappe/model/naming.py”, line 38, in set_new_name
doc.run_method(“autoname”)
File “/home/shahid/meeting/frappe-bench/apps/frappe/frappe/model/document.py”, line 651, in run_method
out = Document.hook(fn)(self, *args, **kwargs)
File “/home/shahid/meeting/frappe-bench/apps/frappe/frappe/model/document.py”, line 858, in composer
return composed(self, method, *args, **kwargs)
File “/home/shahid/meeting/frappe-bench/apps/frappe/frappe/model/document.py”, line 841, in runner
add_to_return_value(self, fn(self, *args, **kwargs))
File “/home/shahid/meeting/frappe-bench/apps/frappe/frappe/model/document.py”, line 645, in
fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
File “/home/shahid/meeting/frappe-bench/apps/frappe/frappe/website/website_generator.py”, line 25, in autoname
self.name = self.scrub(self.get(self.website.page_title_field or “title”))
File “/home/shahid/meeting/frappe-bench/apps/frappe/frappe/website/website_generator.py”, line 52, in scrub
return cleanup_page_name(text).replace('
', ‘-’)
AttributeError: ‘NoneType’ object has no attribute ‘replace’

and when i change .py file to

class Program(Document):

Error is gone and successfully added

but this time error is at

View Website → program/nameofitemadded/

error is

Oops, a server error has occured

Traceback (most recent call last):
File “/home/shahid/meeting/frappe-bench/apps/frappe/frappe/website/render.py”, line 32, in render
data = render_page_by_language(path)
File “/home/shahid/meeting/frappe-bench/apps/frappe/frappe/website/render.py”, line 101, in render_page_by_language
return render_page(path)
File “/home/shahid/meeting/frappe-bench/apps/frappe/frappe/website/render.py”, line 117, in render_page
return build(path)
File “/home/shahid/meeting/frappe-bench/apps/frappe/frappe/website/render.py”, line 124, in build
return build_page(path)
File “/home/shahid/meeting/frappe-bench/apps/frappe/frappe/website/render.py”, line 137, in build_page
context = get_context(path)
File “/home/shahid/meeting/frappe-bench/apps/frappe/frappe/website/context.py”, line 14, in get_context
context = get_page_context(path)
File “/home/shahid/meeting/frappe-bench/apps/frappe/frappe/website/router.py”, line 35, in get_page_context
page_context = make_page_context(path)
File “/home/shahid/meeting/frappe-bench/apps/frappe/frappe/website/router.py”, line 44, in make_page_context
context = resolve_route(path)
File “/home/shahid/meeting/frappe-bench/apps/frappe/frappe/website/router.py”, line 21, in resolve_route
return get_page_context_from_doctype(path)
File “/home/shahid/meeting/frappe-bench/apps/frappe/frappe/website/router.py”, line 77, in get_page_context_from_doctype
return frappe.get_doc(page_info.get(“doctype”), page_info.get(“name”)).get_page_info()
AttributeError: ‘Program’ object has no attribute ‘get_page_info’

please help me to customize webview and add data to doctype same time using single code

thanks

You either need to have a field named title or set page_title_field property in the website properties of the your controller class.

2 Likes

yes it solved my problem thanks

i changed website to this

website = frappe._dict(
template = “templates/generators/program.html”,
condition_field = “show_in_website”,
page_title_field = “program_name”,
)

then error is gone thanks

1 Like

I solve the problem by setting the Title Field in the View Settings section of the Doctype to the name of one of the fields in the Doctype