[Django]-Django: Support for string view arguments to url() is deprecated and will be removed in Django 1.10

50๐Ÿ‘

โœ…

I have found the answer to my question. It was indeed an import error. For Django 1.10, you now have to import the appโ€™s view.py, and then pass the second argument of url() without quotes. Here is my code now in urls.py:

from django.conf.urls import url
from django.contrib import admin
import main.views

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^$', main.views.home)
]

I did not change anything in the app or view.py files.

Props to @Rik Poggi for illustrating how to import in his answer to this question:
Django โ€“ Import views from separate apps

๐Ÿ‘คAMadinger

8๐Ÿ‘

You should be able to use the following:

from django.conf.urls import url
from django.contrib import admin

from main import views

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^$', views.home)
]

Iโ€™m not absolutely certain what your directory structure looks like, but using a relative import such as from . import X is for when the files are in the same folder as each other.

๐Ÿ‘คJoey Wilhelm

3๐Ÿ‘

You can use your functions by importing all of them to list and added each one of them to urlpatterns.

from django.conf.urls import url
from django.contrib import admin

from main.views import(
   home,
   function2,
   function3,
)

urlpatterns = [
   url(r'^admin/', admin.site.urls),
   url(r'^home/$', home),

   url(r'function2/^$', function2),
   url(r'^$', function3),
]
๐Ÿ‘คHarun ERGUL

Leave a comment