我继承了一个Django应用,并注意到urlpatterns += patterns('')
和urls.py
中的等效内容。
e.g。
urlpatterns = patterns(
'',
url(r'^index.html', render_index),
)
#...
urlpatterns += patterns(
'',
url(r'^page.html', another_controller),
)
这是做什么的?什么?
答案 0 :(得分:2)
typedef struct PROFI_tstPartition
{
uint32 xAddressID;
uint32 u32Reserved1;
uint32 xBlockTableAdr;
uint32 u32Reserved2;
uint16 u16NumberOfBlocks;
uint16 u16GlobalProperties;
uint8 au8Reserved[4];
} PROFI_tstPartition;
typedef struct PROFI_tstBlock
{
uint32 xPhysicalAddress;
uint32 u32Reserved1;
uint32 xLogicalAddress;
uint32 u32Reserved2;
uint32 xBlockLength;
uint32 u32Reserved3;
uint32 xSectorSize;
uint32 u32Reserved4;
uint8 u8BlockMemoryType;
uint8 u8Security;
uint16 u16Reserved;
uint16 u16BlockProperties;
uint16 u16Reserved2;
} PROFI_tstBlock;
函数需要它,因为patterns()的第一个参数被用作网址的公共视图前缀。来自文档:
patterns()
更简单地写成:
urlpatterns = patterns('',
(r'^articles/(\d{4})/$', 'news.views.year_archive'),
(r'^articles/(\d{4})/(\d{2})/$', 'news.views.month_archive'),
(r'^articles/(\d{4})/(\d{2})/(\d+)/$', 'news.views.article_detail'),
)
但是,自Django 1.8以来,urlpatterns = patterns('news.views',
(r'^articles/(\d{4})/$', 'year_archive'),
(r'^articles/(\d{4})/(\d{2})/$', 'month_archive'),
(r'^articles/(\d{4})/(\d{2})/(\d+)/$', 'article_detail'),
)
中的urlpatterns
变量是使用简单列表创建的:
urls.py
并且不需要此视图前缀参数。