29👍
In 1.10, you can no longer pass import paths to url()
, you need to pass the actual view function:
from posts.views import post_home
urlpatterns = [
...
url(r'^posts/$', post_home),
]
2👍
Replace your admin url pattern with this
url(r'^admin/', include(admin.site.urls))
So your urls.py becomes :
from django.conf.urls import url, include
from django.contrib import admin
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^posts/$', "posts.views.post_home"), #posts is module and post_home
]
admin urls are callable by include (before 1.9).
- Get a list of python packages used by a Django Project
- How to get coverage data from a django app when running in gunicorn
- Unit testing elastic search inside Django app
1👍
For Django 1.11.2
In the main urls.py write :
from django.conf.urls import include,url
from django.contrib import admin
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^posts/', include("Post.urls")),
]
And in the appname/urls.py file write:
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$',views.post_home),
]
- How to get filtered queryset in django admin?
- Django session key changing upon authentication
- How to I hide my secret_key using virtualenv and Django?
0👍
Answer is in project-dir/urls.py
Including another URLconf 1. Import the include() function: from django.conf.urls import url, include 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
- SerializerClass field on Serializer save from primary key
- Pymongo [SSL: CERTIFICATE_VERIFY_FAILED]: certificate has expired on Mongo Atlas
- Django + Pydev/Eclipse + Google App Engine – possible?
- In MVC (eg. Django) what's the best place to put your heavy logic?
0👍
Just to complement the answer from @knbk, we could use the template below:
as is in 1.9:
from django.conf.urls import url, include
urlpatterns = [
url(r'^admin/', admin.site.urls), #it's not allowed to use the include() in the admin.urls
url(r'^posts/$', include(posts.views.post_home),
]
as should be in 1.10:
from your_project_django.your_app_django.view import name_of_your_view
urlpatterns = [
...
url(r'^name_of_the_view/$', name_of_the_view),
]
Remember to create in your_app_django >> views.py the function to render your view.
- In Django ORM, "values" and "annotate" are not working to group by
- Is a ModelChoiceField always required?
- How to downgrade from Django 1.7 to Django 1.6
0👍
You need to pass actual view function
from posts.views import post_home
urlpatterns = [
…
url(r’^posts/$’, post_home),
]
This works fine!
You can have a read at URL Dispatcher Django
and here Common Reguler Expressions Django URLs
- Daterange on a django-filter
- Django-signals vs triggers?
- Using django-storages and the s3boto backend, How do I add caching info to request headers for an image so browser will cache image?
- Image Conversion – Cannot write mode RGBA as JPEG