Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/maxkb/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def page_not_found(request, exception):
return HttpResponseRedirect(a)
index_path = os.path.join(PROJECT_DIR, 'apps', "static", 'chat', 'index.html')
content = get_index_html(index_path)
content = content.replace("prefix: '/chat'", f"prefix: {CONFIG.get_chat_path()}")
content = content.replace("prefix: '/chat'", f"prefix: '{CONFIG.get_chat_path()}'")
if not os.path.exists(index_path):
return HttpResponse("页面不存在", status=404)
return HttpResponse(content, status=200)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The provided code is mostly correct and optimized for its intended purpose, but there is one minor suggestion to improve clarity:

Original line with potential issue (missing quotes):

content = content.replace("prefix: '/chat'"

Updated line with corrected string handling:

content = content.replace("prefix: '/chat'".strip(), f"prefix: '{CONFIG.get_chat_path()}'")

This ensures that any leading/trailing whitespace in the placeholder text gets removed before replacing it.

Overall, the function appears to correctly handle errors related to pages not found by checking the CONTENT_ROOT directory path using os.path.exists. The replacement logic uses single quotes around the value returned by CONFIG.get_chat_path() to ensure proper JSON formatting.

Expand Down
Loading