Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custome Page not working #748

Open
hernansaa opened this issue Sep 17, 2024 · 3 comments
Open

Custome Page not working #748

hernansaa opened this issue Sep 17, 2024 · 3 comments

Comments

@hernansaa
Copy link

What version of Unfold are you using?

For example: 0.38

What version of Django are you using?

For example: 5.0.6

Did you checked changelog/commit history, if the bug is not already fixed?

For example: Yes

Did you searched other issues, if the bug is not already fixed?

For example: Yes

Did you checked documentation?

Yes.

Describe your issue

Not 100 per cent sure is a bug or is just me, being me.
When trying to create a Custom Page, it seems that the url is not being registered. I have tried different patterns but the urlconf doesn't seem to be aware of the url.
I am using a custom admin (https://unfoldadmin.com/blog/migrating-django-admin-unfold/) and its being working well, But I just cant make the custom page work.
Any help would be greatly appreciated. Thanks.

admin.py


class MyClassBasedView(UnfoldModelAdminViewMixin, TemplateView):
    title = "Custom Title"  # required: custom page header title
    permission_required = () # required: tuple of permissions
    template_name = "admin/quotations/test.html"


@register(Quotation, site=new_admin_site)
class CustomAdmin(ModelAdmin):
    def get_urls(self):
        return super().get_urls() + [
            path(
                "test/",
                MyClassBasedView.as_view(model_admin=self),  # IMPORTANT: model_admin is required
                name="custom_name"
            ),
        ]

I get a Page not found and no trace of the "test/" url.
image

@lukasvinclav
Copy link
Contributor

Hey, I just followed the docs and implemented custom page in the Formula (demo) project without any issues. If you can replicate the issue in separate repository, let me know here and I will check that. Soon, I will update Formula so you will be able to play with the code locally.

@hernansaa
Copy link
Author

Hey, I just followed the docs and implemented custom page in the Formula (demo) project without any issues. If you can replicate the issue in separate repository, let me know here and I will check that. Soon, I will update Formula so you will be able to play with the code locally.

Hola! thanks a lot for the quick response. I have created a new repo to test it (https://github.com/hernansaa/test-custom-page).
Also I have created a new app in the django project called "testpage", where I configure de admin.py and template as per the documentation.
The project hast a app called "core" which has the settings.py in it.
Also, has a gs_admin app where all the configuration for the unfold admin is (loaders.py, sites.py).
I hope this is enough for you to check it, otherwise let me know and will do whatever you need.
Thanks a lot in advance.

@gadonski
Copy link

Hey, I just followed the docs and implemented custom page in the Formula (demo) project without any issues. If you can replicate the issue in separate repository, let me know here and I will check that. Soon, I will update Formula so you will be able to play with the code locally.

Hola! thanks a lot for the quick response. I have created a new repo to test it (https://github.com/hernansaa/test-custom-page). Also I have created a new app in the django project called "testpage", where I configure de admin.py and template as per the documentation. The project hast a app called "core" which has the settings.py in it. Also, has a gs_admin app where all the configuration for the unfold admin is (loaders.py, sites.py). I hope this is enough for you to check it, otherwise let me know and will do whatever you need. Thanks a lot in advance.

try this:

on you custom url set the path without slash

@register(Quotation, site=new_admin_site)

class CustomAdmin(ModelAdmin):
    def get_urls(self):
        return super().get_urls() + [
            path(
               "test",
                MyClassBasedView.as_view(model_admin=self),  # IMPORTANT: model_admin is required
                name="custom_name"
            ),
        ]

in you browser, try the addres with the app name / model name / custom address, eg:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants