Skip to content

Commit

Permalink
Merge pull request #9 from rails-inspire-django/feature/7-preview-cls
Browse files Browse the repository at this point in the history
return 404
  • Loading branch information
michael-yin authored Jun 6, 2024
2 parents adf11b4 + d278c31 commit 5472c09
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/django_lookbook/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,18 @@ def inspect_view(request, slug):

preview_name, example_name = slug.split("/")

preview_cls = get_previews()[preview_name.replace("_component", "")]
preview_cls = get_previews().get(preview_name.replace("_component", ""), None)
if not preview_cls:
return render(
request,
"django_lookbook/404.html",
context={
"sidebar_previews": sidebar_previews,
"previews": get_previews(),
},
status=404,
)

preview_instance = preview_cls()

query_dict = request_get_to_dict(request)
Expand Down Expand Up @@ -240,7 +251,10 @@ def preview_view(request, slug):

preview_name, example_name = slug.split("/")

preview_cls = get_previews()[preview_name.replace("_component", "")]
preview_cls = get_previews().get(preview_name.replace("_component", ""), None)
if not preview_cls:
raise Http404

preview_instance = preview_cls()

query_dict = request_get_to_dict(request)
Expand Down

0 comments on commit 5472c09

Please sign in to comment.