无法访问Django管理面板

huangapple go评论97阅读模式
英文:

unable to access admin panel django

问题

我已更改我的观点,更具体地说是"用于Django的类似Spring的请求映射"的请求映射,因此我必须更改我的URL以按以下方式工作链接到Django的类似Spring请求映射的Pypi文档。然后,尽管我在项目的urls.py中注册了它,但在那次更改后,我无法访问管理面板。

项目的urls.py:

from myapp.views import UserView
from django.contrib import admin

urlpatterns = UrlPattern()

urlpatterns.register(UserView)

urlpatterns += [path('', include('myapp.urls'))]
urlpatterns += [path('admin/', admin.site.urls)]

当然,我已将其导入到我的设置中,它在我进行URL重构之前可以正常工作。我只是想提一下,我喜欢这种工作方式,我的问题是如何修复对管理面板的访问,如果可能的话。

我收到的错误消息是:

当前路径admin/与任何路径都不匹配。

英文:

I have changed my views and more specifically the request-mappings to "spring-like request mappings for djang". There for I had to change my urls to work as follows link to Pypi documentation of spring-like request mappings for django. After that change tho, Im unable to access admin panel, even tho I have it registered in my project urls.py.

Project urls.py:

from myapp.views import UserView
from django.contrib import admin

urlpatterns = UrlPattern()

urlpatterns.register(UserView)

urlpatterns += [path('', include('myapp.urls'))]
urlpatterns += [path('admin/', admin.site.urls)]

Of course I have it imported in my settings, it used to work before that url refactoring I did. I just want to mention that I like this way of work and my question is specifically how do I fix the access to the admin panel, if it is possible ofc.

The error Im getting is:

> The current path, admin/, didn’t match any of these.

答案1

得分: 0

from myapp.views import UserView
from django_request_mapping import UrlPattern
from django.contrib import admin

patterns = UrlPattern()

patterns.register(UserView)

urlpatterns = [
    path('<your_url>', include(patterns.urls)),  # -------> 在这里放入你的 URL
    path('', include('myapp.urls')),
    path('admin/', admin.site.urls)
]

或者,我认为你也可以使用 DRF,而不是 django-request-mapping,因为似乎这个模块不再维护了。

你可以在这里阅读更多信息:
https://www.django-rest-framework.org/api-guide/routers/

https://www.django-rest-framework.org/api-guide/viewsets/#marking-extra-actions-for-routing


<details>
<summary>英文:</summary>

Try this:

from myapp.views import UserView
from django_request_mapping import UrlPattern
from django.contrib import admin

patterns = UrlPattern()

patterns.register(UserView)

urlpatterns = [
path('<you url>', include(patterns.urls)), # ------> Put your url here
path('', include('myapp.urls')),
path('admin/', admin.site.urls)
]


alternatively, I think you can use DRF for this also instead of ```django-request-mapping``` because it seems like this module is not maintained anymore.

You can read more about it here:
https://www.django-rest-framework.org/api-guide/routers/

and

https://www.django-rest-framework.org/api-guide/viewsets/#marking-extra-actions-for-routing

</details>



huangapple
  • 本文由 发表于 2023年8月10日 18:49:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/76875022.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定