Marius Øpstad
Marius Øpstad

Reputation: 1

Wrong code or wrong setup?

I'm pretty new to coding and I've been sitting for the last 5 hours trying to make a website, but it gives me an error straight away. I've been looking all over for a solution but have not yet come by one.

This is the error code:

C:\Projects\bgcenv\myproject\urls.py:26: RemovedInDjango110Warning: Support for
string view arguments to url() is deprecated and will be removed in Django 1.10
(got myproject.views.index). Pass the callable instead.
  url(r'^$', 'myproject.views.index'),

This is my url.py:

from django.contrib import admin
admin.autodiscover()
try:
    from django.conf.urls import url
except ImportError:  # django < 1.4
    from django.conf.urls.defaults import url


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

Upvotes: 0

Views: 71

Answers (1)

Daniel
Daniel

Reputation: 1406

That looks like a warning, not an error, but what it's saying is that the url function (from django.conf.urls) is expecting you to pass a function (or another callable) instead of a string. You need to import index from myproject.views and pass that:

from django.contrib import admin
admin.autodiscover()
try:
    from django.conf.urls import url
except ImportError:  # django < 1.4
    from django.conf.urls.defaults import url

from myproject import views
urlpatterns = [
    url(r'^admin/', admin.site.urls),
    #url(r'^$', 'myproject.views.index'),
    url(r'^$', views.index),
    # Importing the views module you can
    # now conveniently register other views:
    # url('r^/blah/', views.blah),
]

Upvotes: 5

Related Questions