3π
I just tried to recreate this issue. It seems that you are correct and just import views
no longer works. However, the following import statement works fine for me:
from . import views
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^$', views.index)
]
You can see an example here on the django documentation. I also think this related Stack Overflow question can clarify they reason for dot import syntax:
1π
You should include the views.py file from the application that you have created. So try
from <your app name>.views import *
- [Django]-Relative font URLs in CSS cause 403s on S3
- [Django]-Django signals. how to create a unique dispatch id?
- [Django]-Configuring django south with PostgreSQL
- [Django]-Anyone knows a good hack to make django-registration use emails as usernames?
1π
Your statement is a bit of a mix.
Before version 1.8 it was
from myapp import views
urlpatterns = patterns('',
url('^$', views.myview),
url('^other/$', views.otherview),
)
Now, from version 1.8, there is no need for the first void argument to patterns
when assigning urlpatterns
. Actually there is no need to call patterns
at all.
Here is one example form my latest project with Django 1.8:
urlpatterns = [
url(r'^$', HomePage.as_view(), name='home'),
url(r'^play/', include('play.urls', namespace='play', app_name='play')),
]
And as described in the Django 1.8 release docs:
Thus patterns() serves little purpose and is a burden when teaching
new users (answering the newbieβs question βwhy do I need this empty
string as the first argument to patterns()?β). For these reasons, we
are deprecating it. Updating your code is as simple as ensuring that
urlpatterns is a list of django.conf.urls.url() instances.
For example:
from django.conf.urls import url
from myapp import views
urlpatterns = [
url('^$', views.myview),
url('^other/$', views.otherview),
]
- [Django]-Django template syntax error
- [Django]-Simplest framework for converting python app into webapp?