Question 1:
Different django versions have different url styles
There are differences in the configuration of urls.py in django1.8 and urls.py in django1.6
In django1.6:
urlpatterns = patterns(‘’,
url(r'^blog/index/$','blog.views.index'),
url(r'^blog/time/$','blog.views.time'),
)
or
urlpatterns = patterns(‘blog.views’,
url(r'^blog/index/$','index'),
url(r'^blog/time/$','time'),
)
In django1.8:
from blog import views # django1.8 and later versions require that the former improt be used normally
urlpatterns = [
url(r'^blog/index/$',views.index),#Note here, single/double quotation marks are cancelled
url(r'^blog/time/$', views.time),
]
or
urlpatterns = [
url(r'^blog/index/$','blog.views.index'),#Note that single/double quotes can still be used here
url(r'^blog/time/$', ’blog.views.time‘),
]
The first one is recommended in django1.8. There are intelligent reminders and error reporting mechanisms in pycharm, so there will be no errors.
The following is the official document address:
https://docs.djangoproject.com/en/1.8/topics/http/urls/
Reprint: http://www.maiziedu.com/article/8536/
----------------------------------------------------------------------------------------------------------------------
Django 1.7.x and below:
url(r
'^add/(\d+)/(\d+)/$'
,
'calc.views.add2'
, name
=
'add2'
),
|
Django 1.8.x and above:
url(r
'^add/(\d+)/(\d+)/$'
, calc_views.add2, name
=
'add2'
),
(\d+) :数字
name=add2 :name表示要访问的views.py的中方法名。
c = int(a)+int(b)
return HttpResponse(str(c))