django-admin.1 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418
  1. .\" Man page generated from reStructuredText.
  2. .
  3. .TH "DJANGO-ADMIN" "1" "September 23, 2015" "1.9" "Django"
  4. .SH NAME
  5. django-admin \- Utility script for the Django Web framework
  6. .
  7. .nr rst2man-indent-level 0
  8. .
  9. .de1 rstReportMargin
  10. \\$1 \\n[an-margin]
  11. level \\n[rst2man-indent-level]
  12. level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
  13. -
  14. \\n[rst2man-indent0]
  15. \\n[rst2man-indent1]
  16. \\n[rst2man-indent2]
  17. ..
  18. .de1 INDENT
  19. .\" .rstReportMargin pre:
  20. . RS \\$1
  21. . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin]
  22. . nr rst2man-indent-level +1
  23. .\" .rstReportMargin post:
  24. ..
  25. .de UNINDENT
  26. . RE
  27. .\" indent \\n[an-margin]
  28. .\" old: \\n[rst2man-indent\\n[rst2man-indent-level]]
  29. .nr rst2man-indent-level -1
  30. .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
  31. .in \\n[rst2man-indent\\n[rst2man-indent-level]]u
  32. ..
  33. .sp
  34. \fBdjango\-admin\fP is Django\(aqs command\-line utility for administrative tasks.
  35. This document outlines all it can do.
  36. .sp
  37. In addition, \fBmanage.py\fP is automatically created in each Django project.
  38. \fBmanage.py\fP is a thin wrapper around \fBdjango\-admin\fP that takes care of
  39. several things for you before delegating to \fBdjango\-admin\fP:
  40. .INDENT 0.0
  41. .IP \(bu 2
  42. It puts your project\(aqs package on \fBsys.path\fP\&.
  43. .IP \(bu 2
  44. It sets the \fBDJANGO_SETTINGS_MODULE\fP environment variable so that
  45. it points to your project\(aqs \fBsettings.py\fP file.
  46. .IP \(bu 2
  47. It calls \fBdjango.setup()\fP to initialize various internals of Django.
  48. .UNINDENT
  49. .sp
  50. The \fBdjango\-admin\fP script should be on your system path if you installed
  51. Django via its \fBsetup.py\fP utility. If it\(aqs not on your path, you can find it
  52. in \fBsite\-packages/django/bin\fP within your Python installation. Consider
  53. symlinking it from some place on your path, such as \fB/usr/local/bin\fP\&.
  54. .sp
  55. For Windows users, who do not have symlinking functionality available, you can
  56. copy \fBdjango\-admin.exe\fP to a location on your existing path or edit the
  57. \fBPATH\fP settings (under \fBSettings \- Control Panel \- System \- Advanced \-
  58. Environment...\fP) to point to its installed location.
  59. .sp
  60. Generally, when working on a single Django project, it\(aqs easier to use
  61. \fBmanage.py\fP than \fBdjango\-admin\fP\&. If you need to switch between multiple
  62. Django settings files, use \fBdjango\-admin\fP with
  63. \fBDJANGO_SETTINGS_MODULE\fP or the \fI\%\-\-settings\fP command line
  64. option.
  65. .sp
  66. The command\-line examples throughout this document use \fBdjango\-admin\fP to
  67. be consistent, but any example can use \fBmanage.py\fP or \fBpython \-m django\fP
  68. just as well.
  69. .sp
  70. \fBpython \-m django\fP was added.
  71. .SH USAGE
  72. .INDENT 0.0
  73. .INDENT 3.5
  74. .sp
  75. .nf
  76. .ft C
  77. $ django\-admin <command> [options]
  78. $ manage.py <command> [options]
  79. $ python \-m django <command> [options]
  80. .ft P
  81. .fi
  82. .UNINDENT
  83. .UNINDENT
  84. .sp
  85. \fBcommand\fP should be one of the commands listed in this document.
  86. \fBoptions\fP, which is optional, should be zero or more of the options available
  87. for the given command.
  88. .SS Getting runtime help
  89. .INDENT 0.0
  90. .TP
  91. .B django\-admin help
  92. .UNINDENT
  93. .sp
  94. Run \fBdjango\-admin help\fP to display usage information and a list of the
  95. commands provided by each application.
  96. .sp
  97. Run \fBdjango\-admin help \-\-commands\fP to display a list of all available
  98. commands.
  99. .sp
  100. Run \fBdjango\-admin help <command>\fP to display a description of the given
  101. command and a list of its available options.
  102. .SS App names
  103. .sp
  104. Many commands take a list of "app names." An "app name" is the basename of
  105. the package containing your models. For example, if your \fBINSTALLED_APPS\fP
  106. contains the string \fB\(aqmysite.blog\(aq\fP, the app name is \fBblog\fP\&.
  107. .SS Determining the version
  108. .INDENT 0.0
  109. .TP
  110. .B django\-admin version
  111. .UNINDENT
  112. .sp
  113. Run \fBdjango\-admin version\fP to display the current Django version.
  114. .sp
  115. The output follows the schema described in \fI\%PEP 386\fP:
  116. .INDENT 0.0
  117. .INDENT 3.5
  118. .sp
  119. .nf
  120. .ft C
  121. 1.4.dev17026
  122. 1.4a1
  123. 1.4
  124. .ft P
  125. .fi
  126. .UNINDENT
  127. .UNINDENT
  128. .SS Displaying debug output
  129. .sp
  130. Use \fI\%\-\-verbosity\fP to specify the amount of notification and debug information
  131. that \fBdjango\-admin\fP should print to the console. For more details, see the
  132. documentation for the \fI\%\-\-verbosity\fP option.
  133. .SH AVAILABLE COMMANDS
  134. .SS check <appname appname ...>
  135. .INDENT 0.0
  136. .TP
  137. .B django\-admin check
  138. .UNINDENT
  139. .sp
  140. Uses the \fBsystem check framework\fP to inspect
  141. the entire Django project for common problems.
  142. .sp
  143. The system check framework will confirm that there aren\(aqt any problems with
  144. your installed models or your admin registrations. It will also provide warnings
  145. of common compatibility problems introduced by upgrading Django to a new version.
  146. Custom checks may be introduced by other libraries and applications.
  147. .sp
  148. By default, all apps will be checked. You can check a subset of apps by providing
  149. a list of app labels as arguments:
  150. .INDENT 0.0
  151. .INDENT 3.5
  152. .sp
  153. .nf
  154. .ft C
  155. python manage.py check auth admin myapp
  156. .ft P
  157. .fi
  158. .UNINDENT
  159. .UNINDENT
  160. .sp
  161. If you do not specify any app, all apps will be checked.
  162. .INDENT 0.0
  163. .TP
  164. .B \-\-tag <tagname>
  165. .UNINDENT
  166. .sp
  167. The \fBsystem check framework\fP performs many different
  168. types of checks. These check types are categorized with tags. You can use these tags
  169. to restrict the checks performed to just those in a particular category. For example,
  170. to perform only security and compatibility checks, you would run:
  171. .INDENT 0.0
  172. .INDENT 3.5
  173. .sp
  174. .nf
  175. .ft C
  176. python manage.py check \-\-tag security \-\-tag compatibility
  177. .ft P
  178. .fi
  179. .UNINDENT
  180. .UNINDENT
  181. .INDENT 0.0
  182. .TP
  183. .B \-\-list\-tags
  184. .UNINDENT
  185. .sp
  186. List all available tags.
  187. .INDENT 0.0
  188. .TP
  189. .B \-\-deploy
  190. .UNINDENT
  191. .sp
  192. .sp
  193. The \fB\-\-deploy\fP option activates some additional checks that are only relevant
  194. in a deployment setting.
  195. .sp
  196. You can use this option in your local development environment, but since your
  197. local development settings module may not have many of your production settings,
  198. you will probably want to point the \fBcheck\fP command at a different settings
  199. module, either by setting the \fBDJANGO_SETTINGS_MODULE\fP environment variable,
  200. or by passing the \fB\-\-settings\fP option:
  201. .INDENT 0.0
  202. .INDENT 3.5
  203. .sp
  204. .nf
  205. .ft C
  206. python manage.py check \-\-deploy \-\-settings=production_settings
  207. .ft P
  208. .fi
  209. .UNINDENT
  210. .UNINDENT
  211. .sp
  212. Or you could run it directly on a production or staging deployment to verify
  213. that the correct settings are in use (omitting \fB\-\-settings\fP). You could even
  214. make it part of your integration test suite.
  215. .SS compilemessages
  216. .INDENT 0.0
  217. .TP
  218. .B django\-admin compilemessages
  219. .UNINDENT
  220. .sp
  221. Compiles .po files created by \fI\%makemessages\fP to .mo files for use with
  222. the builtin gettext support. See \fB/topics/i18n/index\fP\&.
  223. .sp
  224. Use the \fI\%\-\-locale\fP option (or its shorter version \fB\-l\fP) to
  225. specify the locale(s) to process. If not provided, all locales are processed.
  226. .sp
  227. Use the \fI\%\-\-exclude\fP option (or its shorter version \fB\-x\fP) to
  228. specify the locale(s) to exclude from processing. If not provided, no locales
  229. are excluded.
  230. .sp
  231. You can pass \fB\-\-use\-fuzzy\fP option (or \fB\-f\fP) to include fuzzy translations
  232. into compiled files.
  233. .sp
  234. \fBcompilemessages\fP now matches the operation of \fI\%makemessages\fP,
  235. scanning the project tree for \fB\&.po\fP files to compile.
  236. .sp
  237. Added \fB\-\-exclude\fP and \fB\-\-use\-fuzzy\fP options.
  238. .sp
  239. Example usage:
  240. .INDENT 0.0
  241. .INDENT 3.5
  242. .sp
  243. .nf
  244. .ft C
  245. django\-admin compilemessages \-\-locale=pt_BR
  246. django\-admin compilemessages \-\-locale=pt_BR \-\-locale=fr \-f
  247. django\-admin compilemessages \-l pt_BR
  248. django\-admin compilemessages \-l pt_BR \-l fr \-\-use\-fuzzy
  249. django\-admin compilemessages \-\-exclude=pt_BR
  250. django\-admin compilemessages \-\-exclude=pt_BR \-\-exclude=fr
  251. django\-admin compilemessages \-x pt_BR
  252. django\-admin compilemessages \-x pt_BR \-x fr
  253. .ft P
  254. .fi
  255. .UNINDENT
  256. .UNINDENT
  257. .SS createcachetable
  258. .INDENT 0.0
  259. .TP
  260. .B django\-admin createcachetable
  261. .UNINDENT
  262. .sp
  263. Creates the cache tables for use with the database cache backend using the
  264. information from your settings file. See \fB/topics/cache\fP for more
  265. information.
  266. .sp
  267. The \fI\%\-\-database\fP option can be used to specify the database
  268. onto which the cache table will be installed, but since this information is
  269. pulled from your settings by default, it\(aqs typically not needed.
  270. .sp
  271. The \fI\%\-\-dry\-run\fP option will print the SQL that would be run without
  272. actually running it, so you can customize it or use the migrations framework.
  273. .sp
  274. The \fB\-\-dry\-run\fP option was added.
  275. .SS dbshell
  276. .INDENT 0.0
  277. .TP
  278. .B django\-admin dbshell
  279. .UNINDENT
  280. .sp
  281. Runs the command\-line client for the database engine specified in your
  282. \fBENGINE\fP setting, with the connection parameters specified in your
  283. \fBUSER\fP, \fBPASSWORD\fP, etc., settings.
  284. .INDENT 0.0
  285. .IP \(bu 2
  286. For PostgreSQL, this runs the \fBpsql\fP command\-line client.
  287. .IP \(bu 2
  288. For MySQL, this runs the \fBmysql\fP command\-line client.
  289. .IP \(bu 2
  290. For SQLite, this runs the \fBsqlite3\fP command\-line client.
  291. .IP \(bu 2
  292. For Oracle, this runs the \fBsqlplus\fP command\-line client.
  293. .UNINDENT
  294. .sp
  295. This command assumes the programs are on your \fBPATH\fP so that a simple call to
  296. the program name (\fBpsql\fP, \fBmysql\fP, \fBsqlite3\fP, \fBsqlplus\fP) will find the
  297. program in the right place. There\(aqs no way to specify the location of the
  298. program manually.
  299. .sp
  300. The \fI\%\-\-database\fP option can be used to specify the database
  301. onto which to open a shell.
  302. .SS diffsettings
  303. .INDENT 0.0
  304. .TP
  305. .B django\-admin diffsettings
  306. .UNINDENT
  307. .sp
  308. Displays differences between the current settings file and Django\(aqs default
  309. settings.
  310. .sp
  311. Settings that don\(aqt appear in the defaults are followed by \fB"###"\fP\&. For
  312. example, the default settings don\(aqt define \fBROOT_URLCONF\fP, so
  313. \fBROOT_URLCONF\fP is followed by \fB"###"\fP in the output of
  314. \fBdiffsettings\fP\&.
  315. .sp
  316. The \fI\%\-\-all\fP option may be provided to display all settings, even
  317. if they have Django\(aqs default value. Such settings are prefixed by \fB"###"\fP\&.
  318. .SS dumpdata <app_label app_label app_label.Model ...>
  319. .INDENT 0.0
  320. .TP
  321. .B django\-admin dumpdata
  322. .UNINDENT
  323. .sp
  324. Outputs to standard output all data in the database associated with the named
  325. application(s).
  326. .sp
  327. If no application name is provided, all installed applications will be dumped.
  328. .sp
  329. The output of \fBdumpdata\fP can be used as input for \fI\%loaddata\fP\&.
  330. .sp
  331. Note that \fBdumpdata\fP uses the default manager on the model for selecting the
  332. records to dump. If you\(aqre using a custom manager as
  333. the default manager and it filters some of the available records, not all of the
  334. objects will be dumped.
  335. .sp
  336. The \fI\%\-\-all\fP option may be provided to specify that
  337. \fBdumpdata\fP should use Django\(aqs base manager, dumping records which
  338. might otherwise be filtered or modified by a custom manager.
  339. .INDENT 0.0
  340. .TP
  341. .B \-\-format <fmt>
  342. .UNINDENT
  343. .sp
  344. By default, \fBdumpdata\fP will format its output in JSON, but you can use the
  345. \fB\-\-format\fP option to specify another format. Currently supported formats
  346. are listed in serialization\-formats\&.
  347. .INDENT 0.0
  348. .TP
  349. .B \-\-indent <num>
  350. .UNINDENT
  351. .sp
  352. By default, \fBdumpdata\fP will output all data on a single line. This isn\(aqt
  353. easy for humans to read, so you can use the \fB\-\-indent\fP option to
  354. pretty\-print the output with a number of indentation spaces.
  355. .sp
  356. The \fI\%\-\-exclude\fP option may be provided to prevent specific
  357. applications or models (specified as in the form of \fBapp_label.ModelName\fP)
  358. from being dumped. If you specify a model name to \fBdumpdata\fP, the dumped
  359. output will be restricted to that model, rather than the entire application.
  360. You can also mix application names and model names.
  361. .sp
  362. The \fI\%\-\-database\fP option can be used to specify the database
  363. from which data will be dumped.
  364. .INDENT 0.0
  365. .TP
  366. .B \-\-natural\-foreign
  367. .UNINDENT
  368. .sp
  369. When this option is specified, Django will use the \fBnatural_key()\fP model
  370. method to serialize any foreign key and many\-to\-many relationship to objects of
  371. the type that defines the method. If you are dumping \fBcontrib.auth\fP
  372. \fBPermission\fP objects or \fBcontrib.contenttypes\fP \fBContentType\fP objects, you
  373. should probably be using this flag. See the natural keys documentation for more details on this
  374. and the next option.
  375. .INDENT 0.0
  376. .TP
  377. .B \-\-natural\-primary
  378. .UNINDENT
  379. .sp
  380. When this option is specified, Django will not provide the primary key in the
  381. serialized data of this object since it can be calculated during
  382. deserialization.
  383. .INDENT 0.0
  384. .TP
  385. .B \-\-pks
  386. .UNINDENT
  387. .sp
  388. By default, \fBdumpdata\fP will output all the records of the model, but
  389. you can use the \fB\-\-pks\fP option to specify a comma separated list of
  390. primary keys on which to filter. This is only available when dumping
  391. one model.
  392. .INDENT 0.0
  393. .TP
  394. .B \-\-output
  395. .UNINDENT
  396. .sp
  397. .sp
  398. By default \fBdumpdata\fP will output all the serialized data to standard output.
  399. This option allows you to specify the file to which the data is to be written.
  400. When this option is set and the verbosity is greater than 0 (the default), a
  401. progress bar is shown in the terminal.
  402. .sp
  403. The progress bar in the terminal was added.
  404. .SS flush
  405. .INDENT 0.0
  406. .TP
  407. .B django\-admin flush
  408. .UNINDENT
  409. .sp
  410. Removes all data from the database and re\-executes any post\-synchronization
  411. handlers. The table of which migrations have been applied is not cleared.
  412. .sp
  413. If you would rather start from an empty database and re\-run all migrations, you
  414. should drop and recreate the database and then run \fI\%migrate\fP instead.
  415. .sp
  416. The \fI\%\-\-noinput\fP option may be provided to suppress all user
  417. prompts.
  418. .sp
  419. The \fI\%\-\-database\fP option may be used to specify the database
  420. to flush.
  421. .SS inspectdb
  422. .INDENT 0.0
  423. .TP
  424. .B django\-admin inspectdb
  425. .UNINDENT
  426. .sp
  427. Introspects the database tables in the database pointed\-to by the
  428. \fBNAME\fP setting and outputs a Django model module (a \fBmodels.py\fP
  429. file) to standard output.
  430. .sp
  431. Use this if you have a legacy database with which you\(aqd like to use Django.
  432. The script will inspect the database and create a model for each table within
  433. it.
  434. .sp
  435. As you might expect, the created models will have an attribute for every field
  436. in the table. Note that \fBinspectdb\fP has a few special cases in its field\-name
  437. output:
  438. .INDENT 0.0
  439. .IP \(bu 2
  440. If \fBinspectdb\fP cannot map a column\(aqs type to a model field type, it\(aqll
  441. use \fBTextField\fP and will insert the Python comment
  442. \fB\(aqThis field type is a guess.\(aq\fP next to the field in the generated
  443. model.
  444. .IP \(bu 2
  445. If the database column name is a Python reserved word (such as
  446. \fB\(aqpass\(aq\fP, \fB\(aqclass\(aq\fP or \fB\(aqfor\(aq\fP), \fBinspectdb\fP will append
  447. \fB\(aq_field\(aq\fP to the attribute name. For example, if a table has a column
  448. \fB\(aqfor\(aq\fP, the generated model will have a field \fB\(aqfor_field\(aq\fP, with
  449. the \fBdb_column\fP attribute set to \fB\(aqfor\(aq\fP\&. \fBinspectdb\fP will insert
  450. the Python comment
  451. \fB\(aqField renamed because it was a Python reserved word.\(aq\fP next to the
  452. field.
  453. .UNINDENT
  454. .sp
  455. This feature is meant as a shortcut, not as definitive model generation. After
  456. you run it, you\(aqll want to look over the generated models yourself to make
  457. customizations. In particular, you\(aqll need to rearrange models\(aq order, so that
  458. models that refer to other models are ordered properly.
  459. .sp
  460. Primary keys are automatically introspected for PostgreSQL, MySQL and
  461. SQLite, in which case Django puts in the \fBprimary_key=True\fP where
  462. needed.
  463. .sp
  464. \fBinspectdb\fP works with PostgreSQL, MySQL and SQLite. Foreign\-key detection
  465. only works in PostgreSQL and with certain types of MySQL tables.
  466. .sp
  467. Django doesn\(aqt create database defaults when a
  468. \fBdefault\fP is specified on a model field.
  469. Similarly, database defaults aren\(aqt translated to model field defaults or
  470. detected in any fashion by \fBinspectdb\fP\&.
  471. .sp
  472. By default, \fBinspectdb\fP creates unmanaged models. That is, \fBmanaged = False\fP
  473. in the model\(aqs \fBMeta\fP class tells Django not to manage each table\(aqs creation,
  474. modification, and deletion. If you do want to allow Django to manage the
  475. table\(aqs lifecycle, you\(aqll need to change the
  476. \fBmanaged\fP option to \fBTrue\fP (or simply remove
  477. it because \fBTrue\fP is its default value).
  478. .sp
  479. The \fI\%\-\-database\fP option may be used to specify the
  480. database to introspect.
  481. .SS loaddata <fixture fixture ...>
  482. .INDENT 0.0
  483. .TP
  484. .B django\-admin loaddata
  485. .UNINDENT
  486. .sp
  487. Searches for and loads the contents of the named fixture into the database.
  488. .sp
  489. The \fI\%\-\-database\fP option can be used to specify the database
  490. onto which the data will be loaded.
  491. .INDENT 0.0
  492. .TP
  493. .B \-\-ignorenonexistent
  494. .UNINDENT
  495. .sp
  496. The \fI\%\-\-ignorenonexistent\fP option can be used to ignore fields and
  497. models that may have been removed since the fixture was originally generated.
  498. .INDENT 0.0
  499. .TP
  500. .B \-\-app
  501. .UNINDENT
  502. .sp
  503. The \fI\%\-\-app\fP option can be used to specify a single app to look
  504. for fixtures in rather than looking through all apps.
  505. .sp
  506. \fB\-\-ignorenonexistent\fP also ignores non\-existent models.
  507. .SS What\(aqs a "fixture"?
  508. .sp
  509. A \fIfixture\fP is a collection of files that contain the serialized contents of
  510. the database. Each fixture has a unique name, and the files that comprise the
  511. fixture can be distributed over multiple directories, in multiple applications.
  512. .sp
  513. Django will search in three locations for fixtures:
  514. .INDENT 0.0
  515. .IP 1. 3
  516. In the \fBfixtures\fP directory of every installed application
  517. .IP 2. 3
  518. In any directory named in the \fBFIXTURE_DIRS\fP setting
  519. .IP 3. 3
  520. In the literal path named by the fixture
  521. .UNINDENT
  522. .sp
  523. Django will load any and all fixtures it finds in these locations that match
  524. the provided fixture names.
  525. .sp
  526. If the named fixture has a file extension, only fixtures of that type
  527. will be loaded. For example:
  528. .INDENT 0.0
  529. .INDENT 3.5
  530. .sp
  531. .nf
  532. .ft C
  533. django\-admin loaddata mydata.json
  534. .ft P
  535. .fi
  536. .UNINDENT
  537. .UNINDENT
  538. .sp
  539. would only load JSON fixtures called \fBmydata\fP\&. The fixture extension
  540. must correspond to the registered name of a
  541. serializer (e.g., \fBjson\fP or \fBxml\fP).
  542. .sp
  543. If you omit the extensions, Django will search all available fixture types
  544. for a matching fixture. For example:
  545. .INDENT 0.0
  546. .INDENT 3.5
  547. .sp
  548. .nf
  549. .ft C
  550. django\-admin loaddata mydata
  551. .ft P
  552. .fi
  553. .UNINDENT
  554. .UNINDENT
  555. .sp
  556. would look for any fixture of any fixture type called \fBmydata\fP\&. If a fixture
  557. directory contained \fBmydata.json\fP, that fixture would be loaded
  558. as a JSON fixture.
  559. .sp
  560. The fixtures that are named can include directory components. These
  561. directories will be included in the search path. For example:
  562. .INDENT 0.0
  563. .INDENT 3.5
  564. .sp
  565. .nf
  566. .ft C
  567. django\-admin loaddata foo/bar/mydata.json
  568. .ft P
  569. .fi
  570. .UNINDENT
  571. .UNINDENT
  572. .sp
  573. would search \fB<app_label>/fixtures/foo/bar/mydata.json\fP for each installed
  574. application, \fB<dirname>/foo/bar/mydata.json\fP for each directory in
  575. \fBFIXTURE_DIRS\fP, and the literal path \fBfoo/bar/mydata.json\fP\&.
  576. .sp
  577. When fixture files are processed, the data is saved to the database as is.
  578. Model defined \fBsave()\fP methods are not called, and
  579. any \fBpre_save\fP or
  580. \fBpost_save\fP signals will be called with
  581. \fBraw=True\fP since the instance only contains attributes that are local to the
  582. model. You may, for example, want to disable handlers that access
  583. related fields that aren\(aqt present during fixture loading and would otherwise
  584. raise an exception:
  585. .INDENT 0.0
  586. .INDENT 3.5
  587. .sp
  588. .nf
  589. .ft C
  590. from django.db.models.signals import post_save
  591. from .models import MyModel
  592. def my_handler(**kwargs):
  593. # disable the handler during fixture loading
  594. if kwargs[\(aqraw\(aq]:
  595. return
  596. ...
  597. post_save.connect(my_handler, sender=MyModel)
  598. .ft P
  599. .fi
  600. .UNINDENT
  601. .UNINDENT
  602. .sp
  603. You could also write a simple decorator to encapsulate this logic:
  604. .INDENT 0.0
  605. .INDENT 3.5
  606. .sp
  607. .nf
  608. .ft C
  609. from functools import wraps
  610. def disable_for_loaddata(signal_handler):
  611. """
  612. Decorator that turns off signal handlers when loading fixture data.
  613. """
  614. @wraps(signal_handler)
  615. def wrapper(*args, **kwargs):
  616. if kwargs[\(aqraw\(aq]:
  617. return
  618. signal_handler(*args, **kwargs)
  619. return wrapper
  620. @disable_for_loaddata
  621. def my_handler(**kwargs):
  622. ...
  623. .ft P
  624. .fi
  625. .UNINDENT
  626. .UNINDENT
  627. .sp
  628. Just be aware that this logic will disable the signals whenever fixtures are
  629. deserialized, not just during \fBloaddata\fP\&.
  630. .sp
  631. Note that the order in which fixture files are processed is undefined. However,
  632. all fixture data is installed as a single transaction, so data in
  633. one fixture can reference data in another fixture. If the database backend
  634. supports row\-level constraints, these constraints will be checked at the
  635. end of the transaction.
  636. .sp
  637. The \fI\%dumpdata\fP command can be used to generate input for \fBloaddata\fP\&.
  638. .SS Compressed fixtures
  639. .sp
  640. Fixtures may be compressed in \fBzip\fP, \fBgz\fP, or \fBbz2\fP format. For example:
  641. .INDENT 0.0
  642. .INDENT 3.5
  643. .sp
  644. .nf
  645. .ft C
  646. django\-admin loaddata mydata.json
  647. .ft P
  648. .fi
  649. .UNINDENT
  650. .UNINDENT
  651. .sp
  652. would look for any of \fBmydata.json\fP, \fBmydata.json.zip\fP,
  653. \fBmydata.json.gz\fP, or \fBmydata.json.bz2\fP\&. The first file contained within a
  654. zip\-compressed archive is used.
  655. .sp
  656. Note that if two fixtures with the same name but different
  657. fixture type are discovered (for example, if \fBmydata.json\fP and
  658. \fBmydata.xml.gz\fP were found in the same fixture directory), fixture
  659. installation will be aborted, and any data installed in the call to
  660. \fBloaddata\fP will be removed from the database.
  661. .INDENT 0.0
  662. .INDENT 3.5
  663. .IP "MySQL with MyISAM and fixtures"
  664. .sp
  665. The MyISAM storage engine of MySQL doesn\(aqt support transactions or
  666. constraints, so if you use MyISAM, you won\(aqt get validation of fixture
  667. data, or a rollback if multiple transaction files are found.
  668. .UNINDENT
  669. .UNINDENT
  670. .SS Database\-specific fixtures
  671. .sp
  672. If you\(aqre in a multi\-database setup, you might have fixture data that
  673. you want to load onto one database, but not onto another. In this
  674. situation, you can add a database identifier into the names of your fixtures.
  675. .sp
  676. For example, if your \fBDATABASES\fP setting has a \(aqmaster\(aq database
  677. defined, name the fixture \fBmydata.master.json\fP or
  678. \fBmydata.master.json.gz\fP and the fixture will only be loaded when you
  679. specify you want to load data into the \fBmaster\fP database.
  680. .SS makemessages
  681. .INDENT 0.0
  682. .TP
  683. .B django\-admin makemessages
  684. .UNINDENT
  685. .sp
  686. Runs over the entire source tree of the current directory and pulls out all
  687. strings marked for translation. It creates (or updates) a message file in the
  688. conf/locale (in the Django tree) or locale (for project and application)
  689. directory. After making changes to the messages files you need to compile them
  690. with \fI\%compilemessages\fP for use with the builtin gettext support. See
  691. the i18n documentation for details.
  692. .INDENT 0.0
  693. .TP
  694. .B \-\-all
  695. .UNINDENT
  696. .sp
  697. Use the \fB\-\-all\fP or \fB\-a\fP option to update the message files for all
  698. available languages.
  699. .sp
  700. Example usage:
  701. .INDENT 0.0
  702. .INDENT 3.5
  703. .sp
  704. .nf
  705. .ft C
  706. django\-admin makemessages \-\-all
  707. .ft P
  708. .fi
  709. .UNINDENT
  710. .UNINDENT
  711. .INDENT 0.0
  712. .TP
  713. .B \-\-extension
  714. .UNINDENT
  715. .sp
  716. Use the \fB\-\-extension\fP or \fB\-e\fP option to specify a list of file extensions
  717. to examine (default: ".html", ".txt").
  718. .sp
  719. Example usage:
  720. .INDENT 0.0
  721. .INDENT 3.5
  722. .sp
  723. .nf
  724. .ft C
  725. django\-admin makemessages \-\-locale=de \-\-extension xhtml
  726. .ft P
  727. .fi
  728. .UNINDENT
  729. .UNINDENT
  730. .sp
  731. Separate multiple extensions with commas or use \-e or \-\-extension multiple times:
  732. .INDENT 0.0
  733. .INDENT 3.5
  734. .sp
  735. .nf
  736. .ft C
  737. django\-admin makemessages \-\-locale=de \-\-extension=html,txt \-\-extension xml
  738. .ft P
  739. .fi
  740. .UNINDENT
  741. .UNINDENT
  742. .sp
  743. Use the \fI\%\-\-locale\fP option (or its shorter version \fB\-l\fP) to
  744. specify the locale(s) to process.
  745. .sp
  746. .sp
  747. Use the \fI\%\-\-exclude\fP option (or its shorter version \fB\-x\fP) to
  748. specify the locale(s) to exclude from processing. If not provided, no locales
  749. are excluded.
  750. .sp
  751. Example usage:
  752. .INDENT 0.0
  753. .INDENT 3.5
  754. .sp
  755. .nf
  756. .ft C
  757. django\-admin makemessages \-\-locale=pt_BR
  758. django\-admin makemessages \-\-locale=pt_BR \-\-locale=fr
  759. django\-admin makemessages \-l pt_BR
  760. django\-admin makemessages \-l pt_BR \-l fr
  761. django\-admin makemessages \-\-exclude=pt_BR
  762. django\-admin makemessages \-\-exclude=pt_BR \-\-exclude=fr
  763. django\-admin makemessages \-x pt_BR
  764. django\-admin makemessages \-x pt_BR \-x fr
  765. .ft P
  766. .fi
  767. .UNINDENT
  768. .UNINDENT
  769. .INDENT 0.0
  770. .TP
  771. .B \-\-domain
  772. .UNINDENT
  773. .sp
  774. Use the \fB\-\-domain\fP or \fB\-d\fP option to change the domain of the messages files.
  775. Currently supported:
  776. .INDENT 0.0
  777. .IP \(bu 2
  778. \fBdjango\fP for all \fB*.py\fP, \fB*.html\fP and \fB*.txt\fP files (default)
  779. .IP \(bu 2
  780. \fBdjangojs\fP for \fB*.js\fP files
  781. .UNINDENT
  782. .INDENT 0.0
  783. .TP
  784. .B \-\-symlinks
  785. .UNINDENT
  786. .sp
  787. Use the \fB\-\-symlinks\fP or \fB\-s\fP option to follow symlinks to directories when
  788. looking for new translation strings.
  789. .sp
  790. Example usage:
  791. .INDENT 0.0
  792. .INDENT 3.5
  793. .sp
  794. .nf
  795. .ft C
  796. django\-admin makemessages \-\-locale=de \-\-symlinks
  797. .ft P
  798. .fi
  799. .UNINDENT
  800. .UNINDENT
  801. .INDENT 0.0
  802. .TP
  803. .B \-\-ignore
  804. .UNINDENT
  805. .sp
  806. Use the \fB\-\-ignore\fP or \fB\-i\fP option to ignore files or directories matching
  807. the given \fI\%glob\fP\-style pattern. Use multiple times to ignore more.
  808. .sp
  809. These patterns are used by default: \fB\(aqCVS\(aq\fP, \fB\(aq.*\(aq\fP, \fB\(aq*~\(aq\fP, \fB\(aq*.pyc\(aq\fP
  810. .sp
  811. Example usage:
  812. .INDENT 0.0
  813. .INDENT 3.5
  814. .sp
  815. .nf
  816. .ft C
  817. django\-admin makemessages \-\-locale=en_US \-\-ignore=apps/* \-\-ignore=secret/*.html
  818. .ft P
  819. .fi
  820. .UNINDENT
  821. .UNINDENT
  822. .INDENT 0.0
  823. .TP
  824. .B \-\-no\-default\-ignore
  825. .UNINDENT
  826. .sp
  827. Use the \fB\-\-no\-default\-ignore\fP option to disable the default values of
  828. \fI\%\-\-ignore\fP\&.
  829. .INDENT 0.0
  830. .TP
  831. .B \-\-no\-wrap
  832. .UNINDENT
  833. .sp
  834. Use the \fB\-\-no\-wrap\fP option to disable breaking long message lines into
  835. several lines in language files.
  836. .INDENT 0.0
  837. .TP
  838. .B \-\-no\-location
  839. .UNINDENT
  840. .sp
  841. Use the \fB\-\-no\-location\fP option to suppress writing \(aq\fB#: filename:line\fP
  842. comment lines in language files. Note that using this option makes it harder
  843. for technically skilled translators to understand each message\(aqs context.
  844. .INDENT 0.0
  845. .TP
  846. .B \-\-keep\-pot
  847. .UNINDENT
  848. .sp
  849. Use the \fB\-\-keep\-pot\fP option to prevent Django from deleting the temporary
  850. .pot files it generates before creating the .po file. This is useful for
  851. debugging errors which may prevent the final language files from being created.
  852. .sp
  853. \fBSEE ALSO:\fP
  854. .INDENT 0.0
  855. .INDENT 3.5
  856. See customizing\-makemessages for instructions on how to customize
  857. the keywords that \fI\%makemessages\fP passes to \fBxgettext\fP\&.
  858. .UNINDENT
  859. .UNINDENT
  860. .SS makemigrations [<app_label>]
  861. .INDENT 0.0
  862. .TP
  863. .B django\-admin makemigrations
  864. .UNINDENT
  865. .sp
  866. Creates new migrations based on the changes detected to your models.
  867. Migrations, their relationship with apps and more are covered in depth in
  868. \fBthe migrations documentation\fP\&.
  869. .sp
  870. Providing one or more app names as arguments will limit the migrations created
  871. to the app(s) specified and any dependencies needed (the table at the other end
  872. of a \fBForeignKey\fP, for example).
  873. .sp
  874. .sp
  875. The \fB\-\-noinput\fP option may be provided to suppress all user prompts. If a suppressed
  876. prompt cannot be resolved automatically, the command will exit with error code 3.
  877. .INDENT 0.0
  878. .TP
  879. .B \-\-empty
  880. .UNINDENT
  881. .sp
  882. The \fB\-\-empty\fP option will cause \fBmakemigrations\fP to output an empty
  883. migration for the specified apps, for manual editing. This option is only
  884. for advanced users and should not be used unless you are familiar with
  885. the migration format, migration operations, and the dependencies between
  886. your migrations.
  887. .INDENT 0.0
  888. .TP
  889. .B \-\-dry\-run
  890. .UNINDENT
  891. .sp
  892. The \fB\-\-dry\-run\fP option shows what migrations would be made without
  893. actually writing any migrations files to disk. Using this option along with
  894. \fB\-\-verbosity 3\fP will also show the complete migrations files that would be
  895. written.
  896. .INDENT 0.0
  897. .TP
  898. .B \-\-merge
  899. .UNINDENT
  900. .sp
  901. The \fB\-\-merge\fP option enables fixing of migration conflicts.
  902. .INDENT 0.0
  903. .TP
  904. .B \-\-name, \-n
  905. .UNINDENT
  906. .sp
  907. .sp
  908. The \fB\-\-name\fP option allows you to give the migration(s) a custom name instead
  909. of a generated one.
  910. .INDENT 0.0
  911. .TP
  912. .B \-\-exit, \-e
  913. .UNINDENT
  914. .sp
  915. .sp
  916. The \fB\-\-exit\fP option will cause \fBmakemigrations\fP to exit with error code 1
  917. when no migrations are created (or would have been created, if combined with
  918. \fB\-\-dry\-run\fP).
  919. .SS migrate [<app_label> [<migrationname>]]
  920. .INDENT 0.0
  921. .TP
  922. .B django\-admin migrate
  923. .UNINDENT
  924. .sp
  925. Synchronizes the database state with the current set of models and migrations.
  926. Migrations, their relationship with apps and more are covered in depth in
  927. \fBthe migrations documentation\fP\&.
  928. .sp
  929. The behavior of this command changes depending on the arguments provided:
  930. .INDENT 0.0
  931. .IP \(bu 2
  932. No arguments: All apps have all of their migrations run.
  933. .IP \(bu 2
  934. \fB<app_label>\fP: The specified app has its migrations run, up to the most
  935. recent migration. This may involve running other apps\(aq migrations too, due
  936. to dependencies.
  937. .IP \(bu 2
  938. \fB<app_label> <migrationname>\fP: Brings the database schema to a state where
  939. the named migration is applied, but no later migrations in the same app are
  940. applied. This may involve unapplying migrations if you have previously
  941. migrated past the named migration. Use the name \fBzero\fP to unapply all
  942. migrations for an app.
  943. .UNINDENT
  944. .sp
  945. The \fI\%\-\-database\fP option can be used to specify the database to
  946. migrate.
  947. .INDENT 0.0
  948. .TP
  949. .B \-\-fake
  950. .UNINDENT
  951. .sp
  952. The \fB\-\-fake\fP option tells Django to mark the migrations as having been
  953. applied or unapplied, but without actually running the SQL to change your
  954. database schema.
  955. .sp
  956. This is intended for advanced users to manipulate the
  957. current migration state directly if they\(aqre manually applying changes;
  958. be warned that using \fB\-\-fake\fP runs the risk of putting the migration state
  959. table into a state where manual recovery will be needed to make migrations
  960. run correctly.
  961. .INDENT 0.0
  962. .TP
  963. .B \-\-fake\-initial
  964. .UNINDENT
  965. .sp
  966. .sp
  967. The \fB\-\-fake\-initial\fP option can be used to allow Django to skip an app\(aqs
  968. initial migration if all database tables with the names of all models created
  969. by all \fBCreateModel\fP operations in that
  970. migration already exist. This option is intended for use when first running
  971. migrations against a database that preexisted the use of migrations. This
  972. option does not, however, check for matching database schema beyond matching
  973. table names and so is only safe to use if you are confident that your existing
  974. schema matches what is recorded in your initial migration.
  975. .INDENT 0.0
  976. .TP
  977. .B \-\-run\-syncdb
  978. .UNINDENT
  979. .sp
  980. .sp
  981. The \fB\-\-run\-syncdb\fP option allows creating tables for apps without migrations.
  982. While this isn\(aqt recommended, the migrations framework is sometimes too slow
  983. on large projects with hundreds of models.
  984. .sp
  985. Deprecated since version 1.8: The \fB\-\-list\fP option has been moved to the \fI\%showmigrations\fP
  986. command.
  987. .SS runserver [port or address:port]
  988. .INDENT 0.0
  989. .TP
  990. .B django\-admin runserver
  991. .UNINDENT
  992. .sp
  993. Starts a lightweight development Web server on the local machine. By default,
  994. the server runs on port 8000 on the IP address \fB127.0.0.1\fP\&. You can pass in an
  995. IP address and port number explicitly.
  996. .sp
  997. If you run this script as a user with normal privileges (recommended), you
  998. might not have access to start a port on a low port number. Low port numbers
  999. are reserved for the superuser (root).
  1000. .sp
  1001. This server uses the WSGI application object specified by the
  1002. \fBWSGI_APPLICATION\fP setting.
  1003. .sp
  1004. DO NOT USE THIS SERVER IN A PRODUCTION SETTING. It has not gone through
  1005. security audits or performance tests. (And that\(aqs how it\(aqs gonna stay. We\(aqre in
  1006. the business of making Web frameworks, not Web servers, so improving this
  1007. server to be able to handle a production environment is outside the scope of
  1008. Django.)
  1009. .sp
  1010. The development server automatically reloads Python code for each request, as
  1011. needed. You don\(aqt need to restart the server for code changes to take effect.
  1012. However, some actions like adding files don\(aqt trigger a restart, so you\(aqll
  1013. have to restart the server in these cases.
  1014. .sp
  1015. If you are using Linux and install \fI\%pyinotify\fP, kernel signals will be used to
  1016. autoreload the server (rather than polling file modification timestamps each
  1017. second). This offers better scaling to large projects, reduction in response
  1018. time to code modification, more robust change detection, and battery usage
  1019. reduction.
  1020. .sp
  1021. When you start the server, and each time you change Python code while the
  1022. server is running, the system check framework will check your entire Django
  1023. project for some common errors (see the \fI\%check\fP command). If any
  1024. errors are found, they will be printed to standard output.
  1025. .sp
  1026. You can run as many concurrent servers as you want, as long as they\(aqre on
  1027. separate ports. Just execute \fBdjango\-admin runserver\fP more than once.
  1028. .sp
  1029. Note that the default IP address, \fB127.0.0.1\fP, is not accessible from other
  1030. machines on your network. To make your development server viewable to other
  1031. machines on the network, use its own IP address (e.g. \fB192.168.2.1\fP) or
  1032. \fB0.0.0.0\fP or \fB::\fP (with IPv6 enabled).
  1033. .sp
  1034. You can provide an IPv6 address surrounded by brackets
  1035. (e.g. \fB[200a::1]:8000\fP). This will automatically enable IPv6 support.
  1036. .sp
  1037. A hostname containing ASCII\-only characters can also be used.
  1038. .sp
  1039. If the \fBstaticfiles\fP contrib app is enabled
  1040. (default in new projects) the \fI\%runserver\fP command will be overridden
  1041. with its own runserver command.
  1042. .sp
  1043. If \fI\%migrate\fP was not previously executed, the table that stores the
  1044. history of migrations is created at first run of \fBrunserver\fP\&.
  1045. .INDENT 0.0
  1046. .TP
  1047. .B \-\-noreload
  1048. .UNINDENT
  1049. .sp
  1050. Use the \fB\-\-noreload\fP option to disable the use of the auto\-reloader. This
  1051. means any Python code changes you make while the server is running will \fInot\fP
  1052. take effect if the particular Python modules have already been loaded into
  1053. memory.
  1054. .sp
  1055. Example usage:
  1056. .INDENT 0.0
  1057. .INDENT 3.5
  1058. .sp
  1059. .nf
  1060. .ft C
  1061. django\-admin runserver \-\-noreload
  1062. .ft P
  1063. .fi
  1064. .UNINDENT
  1065. .UNINDENT
  1066. .INDENT 0.0
  1067. .TP
  1068. .B \-\-nothreading
  1069. .UNINDENT
  1070. .sp
  1071. The development server is multithreaded by default. Use the \fB\-\-nothreading\fP
  1072. option to disable the use of threading in the development server.
  1073. .INDENT 0.0
  1074. .TP
  1075. .B \-\-ipv6, \-6
  1076. .UNINDENT
  1077. .sp
  1078. Use the \fB\-\-ipv6\fP (or shorter \fB\-6\fP) option to tell Django to use IPv6 for
  1079. the development server. This changes the default IP address from
  1080. \fB127.0.0.1\fP to \fB::1\fP\&.
  1081. .sp
  1082. Example usage:
  1083. .INDENT 0.0
  1084. .INDENT 3.5
  1085. .sp
  1086. .nf
  1087. .ft C
  1088. django\-admin runserver \-\-ipv6
  1089. .ft P
  1090. .fi
  1091. .UNINDENT
  1092. .UNINDENT
  1093. .SS Examples of using different ports and addresses
  1094. .sp
  1095. Port 8000 on IP address \fB127.0.0.1\fP:
  1096. .INDENT 0.0
  1097. .INDENT 3.5
  1098. .sp
  1099. .nf
  1100. .ft C
  1101. django\-admin runserver
  1102. .ft P
  1103. .fi
  1104. .UNINDENT
  1105. .UNINDENT
  1106. .sp
  1107. Port 8000 on IP address \fB1.2.3.4\fP:
  1108. .INDENT 0.0
  1109. .INDENT 3.5
  1110. .sp
  1111. .nf
  1112. .ft C
  1113. django\-admin runserver 1.2.3.4:8000
  1114. .ft P
  1115. .fi
  1116. .UNINDENT
  1117. .UNINDENT
  1118. .sp
  1119. Port 7000 on IP address \fB127.0.0.1\fP:
  1120. .INDENT 0.0
  1121. .INDENT 3.5
  1122. .sp
  1123. .nf
  1124. .ft C
  1125. django\-admin runserver 7000
  1126. .ft P
  1127. .fi
  1128. .UNINDENT
  1129. .UNINDENT
  1130. .sp
  1131. Port 7000 on IP address \fB1.2.3.4\fP:
  1132. .INDENT 0.0
  1133. .INDENT 3.5
  1134. .sp
  1135. .nf
  1136. .ft C
  1137. django\-admin runserver 1.2.3.4:7000
  1138. .ft P
  1139. .fi
  1140. .UNINDENT
  1141. .UNINDENT
  1142. .sp
  1143. Port 8000 on IPv6 address \fB::1\fP:
  1144. .INDENT 0.0
  1145. .INDENT 3.5
  1146. .sp
  1147. .nf
  1148. .ft C
  1149. django\-admin runserver \-6
  1150. .ft P
  1151. .fi
  1152. .UNINDENT
  1153. .UNINDENT
  1154. .sp
  1155. Port 7000 on IPv6 address \fB::1\fP:
  1156. .INDENT 0.0
  1157. .INDENT 3.5
  1158. .sp
  1159. .nf
  1160. .ft C
  1161. django\-admin runserver \-6 7000
  1162. .ft P
  1163. .fi
  1164. .UNINDENT
  1165. .UNINDENT
  1166. .sp
  1167. Port 7000 on IPv6 address \fB2001:0db8:1234:5678::9\fP:
  1168. .INDENT 0.0
  1169. .INDENT 3.5
  1170. .sp
  1171. .nf
  1172. .ft C
  1173. django\-admin runserver [2001:0db8:1234:5678::9]:7000
  1174. .ft P
  1175. .fi
  1176. .UNINDENT
  1177. .UNINDENT
  1178. .sp
  1179. Port 8000 on IPv4 address of host \fBlocalhost\fP:
  1180. .INDENT 0.0
  1181. .INDENT 3.5
  1182. .sp
  1183. .nf
  1184. .ft C
  1185. django\-admin runserver localhost:8000
  1186. .ft P
  1187. .fi
  1188. .UNINDENT
  1189. .UNINDENT
  1190. .sp
  1191. Port 8000 on IPv6 address of host \fBlocalhost\fP:
  1192. .INDENT 0.0
  1193. .INDENT 3.5
  1194. .sp
  1195. .nf
  1196. .ft C
  1197. django\-admin runserver \-6 localhost:8000
  1198. .ft P
  1199. .fi
  1200. .UNINDENT
  1201. .UNINDENT
  1202. .SS Serving static files with the development server
  1203. .sp
  1204. By default, the development server doesn\(aqt serve any static files for your site
  1205. (such as CSS files, images, things under \fBMEDIA_URL\fP and so forth). If
  1206. you want to configure Django to serve static media, read
  1207. \fB/howto/static\-files/index\fP\&.
  1208. .SS sendtestemail
  1209. .INDENT 0.0
  1210. .TP
  1211. .B django\-admin sendtestemail
  1212. .UNINDENT
  1213. .sp
  1214. .sp
  1215. Sends a test email (to confirm email sending through Django is working) to the
  1216. recipient(s) specified. For example:
  1217. .INDENT 0.0
  1218. .INDENT 3.5
  1219. .sp
  1220. .nf
  1221. .ft C
  1222. django\-admin sendtestemail foo@example.com bar@example.com
  1223. .ft P
  1224. .fi
  1225. .UNINDENT
  1226. .UNINDENT
  1227. .INDENT 0.0
  1228. .TP
  1229. .B \-\-managers
  1230. .UNINDENT
  1231. .sp
  1232. Use the \fB\-\-managers\fP option to mail the email addresses specified in
  1233. \fBMANAGERS\fP using \fBmail_managers()\fP\&.
  1234. .INDENT 0.0
  1235. .TP
  1236. .B \-\-admins
  1237. .UNINDENT
  1238. .sp
  1239. Use the \fB\-\-admins\fP option to mail the email addresses specified in
  1240. \fBADMINS\fP using \fBmail_admins()\fP\&.
  1241. .sp
  1242. Note that you may use any combination of these options together.
  1243. .SS shell
  1244. .INDENT 0.0
  1245. .TP
  1246. .B django\-admin shell
  1247. .UNINDENT
  1248. .sp
  1249. Starts the Python interactive interpreter.
  1250. .sp
  1251. Django will use \fI\%IPython\fP or \fI\%bpython\fP if either is installed. If you have a
  1252. rich shell installed but want to force use of the "plain" Python interpreter,
  1253. use the \fB\-\-plain\fP option, like so:
  1254. .INDENT 0.0
  1255. .INDENT 3.5
  1256. .sp
  1257. .nf
  1258. .ft C
  1259. django\-admin shell \-\-plain
  1260. .ft P
  1261. .fi
  1262. .UNINDENT
  1263. .UNINDENT
  1264. .sp
  1265. If you would like to specify either IPython or bpython as your interpreter if
  1266. you have both installed you can specify an alternative interpreter interface
  1267. with the \fB\-i\fP or \fB\-\-interface\fP options like so:
  1268. .sp
  1269. IPython:
  1270. .INDENT 0.0
  1271. .INDENT 3.5
  1272. .sp
  1273. .nf
  1274. .ft C
  1275. django\-admin shell \-i ipython
  1276. django\-admin shell \-\-interface ipython
  1277. .ft P
  1278. .fi
  1279. .UNINDENT
  1280. .UNINDENT
  1281. .sp
  1282. bpython:
  1283. .INDENT 0.0
  1284. .INDENT 3.5
  1285. .sp
  1286. .nf
  1287. .ft C
  1288. django\-admin shell \-i bpython
  1289. django\-admin shell \-\-interface bpython
  1290. .ft P
  1291. .fi
  1292. .UNINDENT
  1293. .UNINDENT
  1294. .sp
  1295. When the "plain" Python interactive interpreter starts (be it because
  1296. \fB\-\-plain\fP was specified or because no other interactive interface is
  1297. available) it reads the script pointed to by the \fI\%PYTHONSTARTUP\fP
  1298. environment variable and the \fB~/.pythonrc.py\fP script. If you don\(aqt wish this
  1299. behavior you can use the \fB\-\-no\-startup\fP option. e.g.:
  1300. .INDENT 0.0
  1301. .INDENT 3.5
  1302. .sp
  1303. .nf
  1304. .ft C
  1305. django\-admin shell \-\-plain \-\-no\-startup
  1306. .ft P
  1307. .fi
  1308. .UNINDENT
  1309. .UNINDENT
  1310. .SS showmigrations [<app_label> [<app_label>]]
  1311. .INDENT 0.0
  1312. .TP
  1313. .B django\-admin showmigrations
  1314. .UNINDENT
  1315. .sp
  1316. .sp
  1317. Shows all migrations in a project.
  1318. .INDENT 0.0
  1319. .TP
  1320. .B \-\-list, \-l
  1321. .UNINDENT
  1322. .sp
  1323. The \fB\-\-list\fP option lists all of the apps Django knows about, the
  1324. migrations available for each app, and whether or not each migration is
  1325. applied (marked by an \fB[X]\fP next to the migration name).
  1326. .sp
  1327. Apps without migrations are also listed, but have \fB(no migrations)\fP printed
  1328. under them.
  1329. .INDENT 0.0
  1330. .TP
  1331. .B \-\-plan, \-p
  1332. .UNINDENT
  1333. .sp
  1334. The \fB\-\-plan\fP option shows the migration plan Django will follow to apply
  1335. migrations. Any supplied app labels are ignored because the plan might go
  1336. beyond those apps. Same as \fB\-\-list\fP, applied migrations are marked by an
  1337. \fB[X]\fP\&. For a verbosity of 2 and above, all dependencies of a migration will
  1338. also be shown.
  1339. .SS sqlflush
  1340. .INDENT 0.0
  1341. .TP
  1342. .B django\-admin sqlflush
  1343. .UNINDENT
  1344. .sp
  1345. Prints the SQL statements that would be executed for the \fI\%flush\fP
  1346. command.
  1347. .sp
  1348. The \fI\%\-\-database\fP option can be used to specify the database for
  1349. which to print the SQL.
  1350. .SS sqlmigrate <app_label> <migrationname>
  1351. .INDENT 0.0
  1352. .TP
  1353. .B django\-admin sqlmigrate
  1354. .UNINDENT
  1355. .sp
  1356. Prints the SQL for the named migration. This requires an active database
  1357. connection, which it will use to resolve constraint names; this means you must
  1358. generate the SQL against a copy of the database you wish to later apply it on.
  1359. .sp
  1360. Note that \fBsqlmigrate\fP doesn\(aqt colorize its output.
  1361. .sp
  1362. The \fI\%\-\-database\fP option can be used to specify the database for
  1363. which to generate the SQL.
  1364. .INDENT 0.0
  1365. .TP
  1366. .B \-\-backwards
  1367. .UNINDENT
  1368. .sp
  1369. By default, the SQL created is for running the migration in the forwards
  1370. direction. Pass \fB\-\-backwards\fP to generate the SQL for
  1371. unapplying the migration instead.
  1372. .sp
  1373. To increase the readability of the overall SQL output the SQL code
  1374. generated for each migration operation is preceded by the operation\(aqs
  1375. description.
  1376. .SS sqlsequencereset <app_label app_label ...>
  1377. .INDENT 0.0
  1378. .TP
  1379. .B django\-admin sqlsequencereset
  1380. .UNINDENT
  1381. .sp
  1382. Prints the SQL statements for resetting sequences for the given app name(s).
  1383. .sp
  1384. Sequences are indexes used by some database engines to track the next available
  1385. number for automatically incremented fields.
  1386. .sp
  1387. Use this command to generate SQL which will fix cases where a sequence is out
  1388. of sync with its automatically incremented field data.
  1389. .sp
  1390. The \fI\%\-\-database\fP option can be used to specify the database for
  1391. which to print the SQL.
  1392. .SS squashmigrations <app_label> [<start_migration_name>] <migration_name>
  1393. .INDENT 0.0
  1394. .TP
  1395. .B django\-admin squashmigrations
  1396. .UNINDENT
  1397. .sp
  1398. Squashes the migrations for \fBapp_label\fP up to and including \fBmigration_name\fP
  1399. down into fewer migrations, if possible. The resulting squashed migrations
  1400. can live alongside the unsquashed ones safely. For more information,
  1401. please read migration\-squashing\&.
  1402. .sp
  1403. .sp
  1404. When \fBstart_migration_name\fP is given, Django will only include migrations
  1405. starting from and including this migration. This helps to mitigate the
  1406. squashing limitation of \fBRunPython\fP and
  1407. \fBdjango.db.migrations.operations.RunSQL\fP migration operations.
  1408. .INDENT 0.0
  1409. .TP
  1410. .B \-\-no\-optimize
  1411. .UNINDENT
  1412. .sp
  1413. By default, Django will try to optimize the operations in your migrations
  1414. to reduce the size of the resulting file. Pass \fB\-\-no\-optimize\fP if this
  1415. process is failing for you or creating incorrect migrations, though please
  1416. also file a Django bug report about the behavior, as optimization is meant
  1417. to be safe.
  1418. .SS startapp <app_label> [destination]
  1419. .INDENT 0.0
  1420. .TP
  1421. .B django\-admin startapp
  1422. .UNINDENT
  1423. .sp
  1424. Creates a Django app directory structure for the given app name in the current
  1425. directory or the given destination.
  1426. .sp
  1427. By default the directory created contains a \fBmodels.py\fP file and other app
  1428. template files. (See the \fI\%source\fP for more details.) If only the app
  1429. name is given, the app directory will be created in the current working
  1430. directory.
  1431. .sp
  1432. If the optional destination is provided, Django will use that existing
  1433. directory rather than creating a new one. You can use \(aq.\(aq to denote the current
  1434. working directory.
  1435. .sp
  1436. For example:
  1437. .INDENT 0.0
  1438. .INDENT 3.5
  1439. .sp
  1440. .nf
  1441. .ft C
  1442. django\-admin startapp myapp /Users/jezdez/Code/myapp
  1443. .ft P
  1444. .fi
  1445. .UNINDENT
  1446. .UNINDENT
  1447. .INDENT 0.0
  1448. .TP
  1449. .B \-\-template
  1450. .UNINDENT
  1451. .sp
  1452. With the \fB\-\-template\fP option, you can use a custom app template by providing
  1453. either the path to a directory with the app template file, or a path to a
  1454. compressed file (\fB\&.tar.gz\fP, \fB\&.tar.bz2\fP, \fB\&.tgz\fP, \fB\&.tbz\fP, \fB\&.zip\fP)
  1455. containing the app template files.
  1456. .sp
  1457. For example, this would look for an app template in the given directory when
  1458. creating the \fBmyapp\fP app:
  1459. .INDENT 0.0
  1460. .INDENT 3.5
  1461. .sp
  1462. .nf
  1463. .ft C
  1464. django\-admin startapp \-\-template=/Users/jezdez/Code/my_app_template myapp
  1465. .ft P
  1466. .fi
  1467. .UNINDENT
  1468. .UNINDENT
  1469. .sp
  1470. Django will also accept URLs (\fBhttp\fP, \fBhttps\fP, \fBftp\fP) to compressed
  1471. archives with the app template files, downloading and extracting them on the
  1472. fly.
  1473. .sp
  1474. For example, taking advantage of Github\(aqs feature to expose repositories as
  1475. zip files, you can use a URL like:
  1476. .INDENT 0.0
  1477. .INDENT 3.5
  1478. .sp
  1479. .nf
  1480. .ft C
  1481. django\-admin startapp \-\-template=https://github.com/githubuser/django\-app\-template/archive/master.zip myapp
  1482. .ft P
  1483. .fi
  1484. .UNINDENT
  1485. .UNINDENT
  1486. .sp
  1487. When Django copies the app template files, it also renders certain files
  1488. through the template engine: the files whose extensions match the
  1489. \fB\-\-extension\fP option (\fBpy\fP by default) and the files whose names are passed
  1490. with the \fB\-\-name\fP option. The \fBtemplate context\fP used is:
  1491. .INDENT 0.0
  1492. .IP \(bu 2
  1493. Any option passed to the \fBstartapp\fP command (among the command\(aqs supported
  1494. options)
  1495. .IP \(bu 2
  1496. \fBapp_name\fP \-\- the app name as passed to the command
  1497. .IP \(bu 2
  1498. \fBapp_directory\fP \-\- the full path of the newly created app
  1499. .IP \(bu 2
  1500. \fBcamel_case_app_name\fP \-\- the app name in camel case format
  1501. .IP \(bu 2
  1502. \fBdocs_version\fP \-\- the version of the documentation: \fB\(aqdev\(aq\fP or \fB\(aq1.x\(aq\fP
  1503. .UNINDENT
  1504. .sp
  1505. \fBcamel_case_app_name\fP was added.
  1506. .sp
  1507. \fBWARNING:\fP
  1508. .INDENT 0.0
  1509. .INDENT 3.5
  1510. When the app template files are rendered with the Django template
  1511. engine (by default all \fB*.py\fP files), Django will also replace all
  1512. stray template variables contained. For example, if one of the Python files
  1513. contains a docstring explaining a particular feature related
  1514. to template rendering, it might result in an incorrect example.
  1515. .sp
  1516. To work around this problem, you can use the \fBtemplatetag\fP
  1517. templatetag to "escape" the various parts of the template syntax.
  1518. .UNINDENT
  1519. .UNINDENT
  1520. .SS startproject <projectname> [destination]
  1521. .INDENT 0.0
  1522. .TP
  1523. .B django\-admin startproject
  1524. .UNINDENT
  1525. .sp
  1526. Creates a Django project directory structure for the given project name in
  1527. the current directory or the given destination.
  1528. .sp
  1529. By default, the new directory contains \fBmanage.py\fP and a project package
  1530. (containing a \fBsettings.py\fP and other files). See the \fI\%template source\fP for
  1531. details.
  1532. .sp
  1533. If only the project name is given, both the project directory and project
  1534. package will be named \fB<projectname>\fP and the project directory
  1535. will be created in the current working directory.
  1536. .sp
  1537. If the optional destination is provided, Django will use that existing
  1538. directory as the project directory, and create \fBmanage.py\fP and the project
  1539. package within it. Use \(aq.\(aq to denote the current working directory.
  1540. .sp
  1541. For example:
  1542. .INDENT 0.0
  1543. .INDENT 3.5
  1544. .sp
  1545. .nf
  1546. .ft C
  1547. django\-admin startproject myproject /Users/jezdez/Code/myproject_repo
  1548. .ft P
  1549. .fi
  1550. .UNINDENT
  1551. .UNINDENT
  1552. .sp
  1553. As with the \fI\%startapp\fP command, the \fB\-\-template\fP option lets you
  1554. specify a directory, file path or URL of a custom project template. See the
  1555. \fI\%startapp\fP documentation for details of supported project template
  1556. formats.
  1557. .sp
  1558. For example, this would look for a project template in the given directory
  1559. when creating the \fBmyproject\fP project:
  1560. .INDENT 0.0
  1561. .INDENT 3.5
  1562. .sp
  1563. .nf
  1564. .ft C
  1565. django\-admin startproject \-\-template=/Users/jezdez/Code/my_project_template myproject
  1566. .ft P
  1567. .fi
  1568. .UNINDENT
  1569. .UNINDENT
  1570. .sp
  1571. Django will also accept URLs (\fBhttp\fP, \fBhttps\fP, \fBftp\fP) to compressed
  1572. archives with the project template files, downloading and extracting them on the
  1573. fly.
  1574. .sp
  1575. For example, taking advantage of Github\(aqs feature to expose repositories as
  1576. zip files, you can use a URL like:
  1577. .INDENT 0.0
  1578. .INDENT 3.5
  1579. .sp
  1580. .nf
  1581. .ft C
  1582. django\-admin startproject \-\-template=https://github.com/githubuser/django\-project\-template/archive/master.zip myproject
  1583. .ft P
  1584. .fi
  1585. .UNINDENT
  1586. .UNINDENT
  1587. .sp
  1588. When Django copies the project template files, it also renders certain files
  1589. through the template engine: the files whose extensions match the
  1590. \fB\-\-extension\fP option (\fBpy\fP by default) and the files whose names are passed
  1591. with the \fB\-\-name\fP option. The \fBtemplate context\fP used is:
  1592. .INDENT 0.0
  1593. .IP \(bu 2
  1594. Any option passed to the \fBstartproject\fP command (among the command\(aqs
  1595. supported options)
  1596. .IP \(bu 2
  1597. \fBproject_name\fP \-\- the project name as passed to the command
  1598. .IP \(bu 2
  1599. \fBproject_directory\fP \-\- the full path of the newly created project
  1600. .IP \(bu 2
  1601. \fBsecret_key\fP \-\- a random key for the \fBSECRET_KEY\fP setting
  1602. .IP \(bu 2
  1603. \fBdocs_version\fP \-\- the version of the documentation: \fB\(aqdev\(aq\fP or \fB\(aq1.x\(aq\fP
  1604. .UNINDENT
  1605. .sp
  1606. Please also see the \fI\%rendering warning\fP as mentioned
  1607. for \fI\%startapp\fP\&.
  1608. .SS test <app or test identifier>
  1609. .INDENT 0.0
  1610. .TP
  1611. .B django\-admin test
  1612. .UNINDENT
  1613. .sp
  1614. Runs tests for all installed models. See \fB/topics/testing/index\fP for more
  1615. information.
  1616. .INDENT 0.0
  1617. .TP
  1618. .B \-\-failfast
  1619. .UNINDENT
  1620. .sp
  1621. The \fB\-\-failfast\fP option can be used to stop running tests and report the
  1622. failure immediately after a test fails.
  1623. .INDENT 0.0
  1624. .TP
  1625. .B \-\-testrunner
  1626. .UNINDENT
  1627. .sp
  1628. The \fB\-\-testrunner\fP option can be used to control the test runner class that
  1629. is used to execute tests. If this value is provided, it overrides the value
  1630. provided by the \fBTEST_RUNNER\fP setting.
  1631. .INDENT 0.0
  1632. .TP
  1633. .B \-\-liveserver
  1634. .UNINDENT
  1635. .sp
  1636. The \fB\-\-liveserver\fP option can be used to override the default address where
  1637. the live server (used with \fBLiveServerTestCase\fP) is
  1638. expected to run from. The default value is \fBlocalhost:8081\-8179\fP\&.
  1639. .sp
  1640. In earlier versions, the default value was \fBlocalhost:8081\fP\&.
  1641. .INDENT 0.0
  1642. .TP
  1643. .B \-\-keepdb
  1644. .UNINDENT
  1645. .sp
  1646. .sp
  1647. The \fB\-\-keepdb\fP option can be used to preserve the test database between test
  1648. runs. This has the advantage of skipping both the create and destroy actions
  1649. which can greatly decrease the time to run tests, especially those in a large
  1650. test suite. If the test database does not exist, it will be created on the first
  1651. run and then preserved for each subsequent run. Any unapplied migrations will also
  1652. be applied to the test database before running the test suite.
  1653. .INDENT 0.0
  1654. .TP
  1655. .B \-\-reverse
  1656. .UNINDENT
  1657. .sp
  1658. .sp
  1659. The \fB\-\-reverse\fP option can be used to sort test cases in the opposite order.
  1660. This may help in debugging the side effects of tests that aren\(aqt properly
  1661. isolated. Grouping by test class is preserved when using
  1662. this option.
  1663. .INDENT 0.0
  1664. .TP
  1665. .B \-\-debug\-sql
  1666. .UNINDENT
  1667. .sp
  1668. .sp
  1669. The \fB\-\-debug\-sql\fP option can be used to enable SQL logging for failing tests. If \fI\%\-\-verbosity\fP is \fB2\fP,
  1670. then queries in passing tests are also output.
  1671. .INDENT 0.0
  1672. .TP
  1673. .B \-\-parallel
  1674. .UNINDENT
  1675. .sp
  1676. .sp
  1677. The \fB\-\-parallel\fP option can be used to run tests in parallel in separate
  1678. processes. Since modern processors have multiple cores, this allows running
  1679. tests significantly faster.
  1680. .sp
  1681. By default \fB\-\-parallel\fP runs one process per core according to
  1682. \fI\%multiprocessing.cpu_count()\fP\&. You can adjust the number of processes
  1683. either by providing it as the option\(aqs value, e.g. \fB\-\-parallel=4\fP, or by
  1684. setting the \fBDJANGO_TEST_PROCESSES\fP environment variable.
  1685. .sp
  1686. Django distributes test cases — \fI\%unittest.TestCase\fP subclasses — to
  1687. subprocesses. If there are fewer test cases than configured processes, Django
  1688. will reduce the number of processes accordingly.
  1689. .sp
  1690. Each process gets its own database. You must ensure that different test cases
  1691. don\(aqt access the same resources. For instance, test cases that touch the
  1692. filesystem should create a temporary directory for their own use.
  1693. .sp
  1694. This option requires the third\-party \fBtblib\fP package to display tracebacks
  1695. correctly:
  1696. .INDENT 0.0
  1697. .INDENT 3.5
  1698. .sp
  1699. .nf
  1700. .ft C
  1701. $ pip install tblib
  1702. .ft P
  1703. .fi
  1704. .UNINDENT
  1705. .UNINDENT
  1706. .sp
  1707. This feature isn\(aqt available on Windows. It doesn\(aqt work with the Oracle
  1708. database backend either.
  1709. .sp
  1710. \fBWARNING:\fP
  1711. .INDENT 0.0
  1712. .INDENT 3.5
  1713. When test parallelization is enabled and a test fails, Django may be
  1714. unable to display the exception traceback. This can make debugging
  1715. difficult. If you encounter this problem, run the affected test without
  1716. parallelization to see the traceback of the failure.
  1717. .sp
  1718. This is a known limitation. It arises from the need to serialize objects
  1719. in order to exchange them between processes. See
  1720. \fI\%What can be pickled and unpickled?\fP for details.
  1721. .UNINDENT
  1722. .UNINDENT
  1723. .SS testserver <fixture fixture ...>
  1724. .INDENT 0.0
  1725. .TP
  1726. .B django\-admin testserver
  1727. .UNINDENT
  1728. .sp
  1729. Runs a Django development server (as in \fI\%runserver\fP) using data from
  1730. the given fixture(s).
  1731. .sp
  1732. For example, this command:
  1733. .INDENT 0.0
  1734. .INDENT 3.5
  1735. .sp
  1736. .nf
  1737. .ft C
  1738. django\-admin testserver mydata.json
  1739. .ft P
  1740. .fi
  1741. .UNINDENT
  1742. .UNINDENT
  1743. .sp
  1744. \&...would perform the following steps:
  1745. .INDENT 0.0
  1746. .IP 1. 3
  1747. Create a test database, as described in the\-test\-database\&.
  1748. .IP 2. 3
  1749. Populate the test database with fixture data from the given fixtures.
  1750. (For more on fixtures, see the documentation for \fI\%loaddata\fP above.)
  1751. .IP 3. 3
  1752. Runs the Django development server (as in \fI\%runserver\fP), pointed at
  1753. this newly created test database instead of your production database.
  1754. .UNINDENT
  1755. .sp
  1756. This is useful in a number of ways:
  1757. .INDENT 0.0
  1758. .IP \(bu 2
  1759. When you\(aqre writing \fBunit tests\fP of how your views
  1760. act with certain fixture data, you can use \fBtestserver\fP to interact with
  1761. the views in a Web browser, manually.
  1762. .IP \(bu 2
  1763. Let\(aqs say you\(aqre developing your Django application and have a "pristine"
  1764. copy of a database that you\(aqd like to interact with. You can dump your
  1765. database to a fixture (using the \fI\%dumpdata\fP command, explained
  1766. above), then use \fBtestserver\fP to run your Web application with that data.
  1767. With this arrangement, you have the flexibility of messing up your data
  1768. in any way, knowing that whatever data changes you\(aqre making are only
  1769. being made to a test database.
  1770. .UNINDENT
  1771. .sp
  1772. Note that this server does \fInot\fP automatically detect changes to your Python
  1773. source code (as \fI\%runserver\fP does). It does, however, detect changes to
  1774. templates.
  1775. .INDENT 0.0
  1776. .TP
  1777. .B \-\-addrport [port number or ipaddr:port]
  1778. .UNINDENT
  1779. .sp
  1780. Use \fB\-\-addrport\fP to specify a different port, or IP address and port, from
  1781. the default of \fB127.0.0.1:8000\fP\&. This value follows exactly the same format and
  1782. serves exactly the same function as the argument to the \fI\%runserver\fP
  1783. command.
  1784. .sp
  1785. Examples:
  1786. .sp
  1787. To run the test server on port 7000 with \fBfixture1\fP and \fBfixture2\fP:
  1788. .INDENT 0.0
  1789. .INDENT 3.5
  1790. .sp
  1791. .nf
  1792. .ft C
  1793. django\-admin testserver \-\-addrport 7000 fixture1 fixture2
  1794. django\-admin testserver fixture1 fixture2 \-\-addrport 7000
  1795. .ft P
  1796. .fi
  1797. .UNINDENT
  1798. .UNINDENT
  1799. .sp
  1800. (The above statements are equivalent. We include both of them to demonstrate
  1801. that it doesn\(aqt matter whether the options come before or after the fixture
  1802. arguments.)
  1803. .sp
  1804. To run on 1.2.3.4:7000 with a \fBtest\fP fixture:
  1805. .INDENT 0.0
  1806. .INDENT 3.5
  1807. .sp
  1808. .nf
  1809. .ft C
  1810. django\-admin testserver \-\-addrport 1.2.3.4:7000 test
  1811. .ft P
  1812. .fi
  1813. .UNINDENT
  1814. .UNINDENT
  1815. .sp
  1816. The \fI\%\-\-noinput\fP option may be provided to suppress all user
  1817. prompts.
  1818. .SH COMMANDS PROVIDED BY APPLICATIONS
  1819. .sp
  1820. Some commands are only available when the \fBdjango.contrib\fP application that
  1821. \fBimplements\fP them has been
  1822. \fBenabled\fP\&. This section describes them grouped by
  1823. their application.
  1824. .SS \fBdjango.contrib.auth\fP
  1825. .SS changepassword
  1826. .INDENT 0.0
  1827. .TP
  1828. .B django\-admin changepassword
  1829. .UNINDENT
  1830. .sp
  1831. This command is only available if Django\(aqs \fBauthentication system\fP (\fBdjango.contrib.auth\fP) is installed.
  1832. .sp
  1833. Allows changing a user\(aqs password. It prompts you to enter a new password twice
  1834. for the given user. If the entries are identical, this immediately becomes the
  1835. new password. If you do not supply a user, the command will attempt to change
  1836. the password whose username matches the current user.
  1837. .sp
  1838. Use the \fB\-\-database\fP option to specify the database to query for the user. If
  1839. it\(aqs not supplied, Django will use the \fBdefault\fP database.
  1840. .sp
  1841. Example usage:
  1842. .INDENT 0.0
  1843. .INDENT 3.5
  1844. .sp
  1845. .nf
  1846. .ft C
  1847. django\-admin changepassword ringo
  1848. .ft P
  1849. .fi
  1850. .UNINDENT
  1851. .UNINDENT
  1852. .SS createsuperuser
  1853. .INDENT 0.0
  1854. .TP
  1855. .B django\-admin createsuperuser
  1856. .UNINDENT
  1857. .sp
  1858. This command is only available if Django\(aqs \fBauthentication system\fP (\fBdjango.contrib.auth\fP) is installed.
  1859. .sp
  1860. Creates a superuser account (a user who has all permissions). This is
  1861. useful if you need to create an initial superuser account or if you need to
  1862. programmatically generate superuser accounts for your site(s).
  1863. .sp
  1864. When run interactively, this command will prompt for a password for
  1865. the new superuser account. When run non\-interactively, no password
  1866. will be set, and the superuser account will not be able to log in until
  1867. a password has been manually set for it.
  1868. .INDENT 0.0
  1869. .TP
  1870. .B \-\-username
  1871. .UNINDENT
  1872. .INDENT 0.0
  1873. .TP
  1874. .B \-\-email
  1875. .UNINDENT
  1876. .sp
  1877. The username and email address for the new account can be supplied by
  1878. using the \fB\-\-username\fP and \fB\-\-email\fP arguments on the command
  1879. line. If either of those is not supplied, \fBcreatesuperuser\fP will prompt for
  1880. it when running interactively.
  1881. .sp
  1882. Use the \fB\-\-database\fP option to specify the database into which the superuser
  1883. object will be saved.
  1884. .sp
  1885. .sp
  1886. You can subclass the management command and override \fBget_input_data()\fP if you
  1887. want to customize data input and validation. Consult the source code for
  1888. details on the existing implementation and the method\(aqs parameters. For example,
  1889. it could be useful if you have a \fBForeignKey\fP in
  1890. \fBREQUIRED_FIELDS\fP and want to
  1891. allow creating an instance instead of entering the primary key of an existing
  1892. instance.
  1893. .SS \fBdjango.contrib.gis\fP
  1894. .SS ogrinspect
  1895. .sp
  1896. This command is only available if \fBGeoDjango\fP
  1897. (\fBdjango.contrib.gis\fP) is installed.
  1898. .sp
  1899. Please refer to its \fBdescription\fP in the GeoDjango
  1900. documentation.
  1901. .SS \fBdjango.contrib.sessions\fP
  1902. .SS clearsessions
  1903. .INDENT 0.0
  1904. .TP
  1905. .B django\-admin clearsessions
  1906. .UNINDENT
  1907. .sp
  1908. Can be run as a cron job or directly to clean out expired sessions.
  1909. .SS \fBdjango.contrib.sitemaps\fP
  1910. .SS ping_google
  1911. .sp
  1912. This command is only available if the \fBSitemaps framework\fP (\fBdjango.contrib.sitemaps\fP) is installed.
  1913. .sp
  1914. Please refer to its \fBdescription\fP in the Sitemaps
  1915. documentation.
  1916. .SS \fBdjango.contrib.staticfiles\fP
  1917. .SS collectstatic
  1918. .sp
  1919. This command is only available if the \fBstatic files application\fP (\fBdjango.contrib.staticfiles\fP) is installed.
  1920. .sp
  1921. Please refer to its \fBdescription\fP in the
  1922. \fBstaticfiles\fP documentation.
  1923. .SS findstatic
  1924. .sp
  1925. This command is only available if the \fBstatic files application\fP (\fBdjango.contrib.staticfiles\fP) is installed.
  1926. .sp
  1927. Please refer to its \fBdescription\fP in the \fBstaticfiles\fP documentation.
  1928. .SH DEFAULT OPTIONS
  1929. .sp
  1930. Although some commands may allow their own custom options, every command
  1931. allows for the following options:
  1932. .INDENT 0.0
  1933. .TP
  1934. .B \-\-pythonpath
  1935. .UNINDENT
  1936. .sp
  1937. Example usage:
  1938. .INDENT 0.0
  1939. .INDENT 3.5
  1940. .sp
  1941. .nf
  1942. .ft C
  1943. django\-admin migrate \-\-pythonpath=\(aq/home/djangoprojects/myproject\(aq
  1944. .ft P
  1945. .fi
  1946. .UNINDENT
  1947. .UNINDENT
  1948. .sp
  1949. Adds the given filesystem path to the Python \fI\%import search path\fP\&. If this
  1950. isn\(aqt provided, \fBdjango\-admin\fP will use the \fBPYTHONPATH\fP environment
  1951. variable.
  1952. .sp
  1953. Note that this option is unnecessary in \fBmanage.py\fP, because it takes care of
  1954. setting the Python path for you.
  1955. .INDENT 0.0
  1956. .TP
  1957. .B \-\-settings
  1958. .UNINDENT
  1959. .sp
  1960. Example usage:
  1961. .INDENT 0.0
  1962. .INDENT 3.5
  1963. .sp
  1964. .nf
  1965. .ft C
  1966. django\-admin migrate \-\-settings=mysite.settings
  1967. .ft P
  1968. .fi
  1969. .UNINDENT
  1970. .UNINDENT
  1971. .sp
  1972. Explicitly specifies the settings module to use. The settings module should be
  1973. in Python package syntax, e.g. \fBmysite.settings\fP\&. If this isn\(aqt provided,
  1974. \fBdjango\-admin\fP will use the \fBDJANGO_SETTINGS_MODULE\fP environment
  1975. variable.
  1976. .sp
  1977. Note that this option is unnecessary in \fBmanage.py\fP, because it uses
  1978. \fBsettings.py\fP from the current project by default.
  1979. .INDENT 0.0
  1980. .TP
  1981. .B \-\-traceback
  1982. .UNINDENT
  1983. .sp
  1984. Example usage:
  1985. .INDENT 0.0
  1986. .INDENT 3.5
  1987. .sp
  1988. .nf
  1989. .ft C
  1990. django\-admin migrate \-\-traceback
  1991. .ft P
  1992. .fi
  1993. .UNINDENT
  1994. .UNINDENT
  1995. .sp
  1996. By default, \fBdjango\-admin\fP will show a simple error message whenever a
  1997. \fBCommandError\fP occurs, but a full stack trace
  1998. for any other exception. If you specify \fB\-\-traceback\fP, \fBdjango\-admin\fP
  1999. will also output a full stack trace when a \fBCommandError\fP is raised.
  2000. .INDENT 0.0
  2001. .TP
  2002. .B \-\-verbosity
  2003. .UNINDENT
  2004. .sp
  2005. Example usage:
  2006. .INDENT 0.0
  2007. .INDENT 3.5
  2008. .sp
  2009. .nf
  2010. .ft C
  2011. django\-admin migrate \-\-verbosity 2
  2012. .ft P
  2013. .fi
  2014. .UNINDENT
  2015. .UNINDENT
  2016. .sp
  2017. Use \fB\-\-verbosity\fP to specify the amount of notification and debug information
  2018. that \fBdjango\-admin\fP should print to the console.
  2019. .INDENT 0.0
  2020. .IP \(bu 2
  2021. \fB0\fP means no output.
  2022. .IP \(bu 2
  2023. \fB1\fP means normal output (default).
  2024. .IP \(bu 2
  2025. \fB2\fP means verbose output.
  2026. .IP \(bu 2
  2027. \fB3\fP means \fIvery\fP verbose output.
  2028. .UNINDENT
  2029. .INDENT 0.0
  2030. .TP
  2031. .B \-\-no\-color
  2032. .UNINDENT
  2033. .sp
  2034. Example usage:
  2035. .INDENT 0.0
  2036. .INDENT 3.5
  2037. .sp
  2038. .nf
  2039. .ft C
  2040. django\-admin sqlall \-\-no\-color
  2041. .ft P
  2042. .fi
  2043. .UNINDENT
  2044. .UNINDENT
  2045. .sp
  2046. By default, \fBdjango\-admin\fP will format the output to be colorized. For
  2047. example, errors will be printed to the console in red and SQL statements will
  2048. be syntax highlighted. To prevent this and have a plain text output, pass the
  2049. \fB\-\-no\-color\fP option when running your command.
  2050. .SH COMMON OPTIONS
  2051. .sp
  2052. The following options are not available on every command, but they are common
  2053. to a number of commands.
  2054. .INDENT 0.0
  2055. .TP
  2056. .B \-\-database
  2057. .UNINDENT
  2058. .sp
  2059. Used to specify the database on which a command will operate. If not
  2060. specified, this option will default to an alias of \fBdefault\fP\&.
  2061. .sp
  2062. For example, to dump data from the database with the alias \fBmaster\fP:
  2063. .INDENT 0.0
  2064. .INDENT 3.5
  2065. .sp
  2066. .nf
  2067. .ft C
  2068. django\-admin dumpdata \-\-database=master
  2069. .ft P
  2070. .fi
  2071. .UNINDENT
  2072. .UNINDENT
  2073. .INDENT 0.0
  2074. .TP
  2075. .B \-\-exclude
  2076. .UNINDENT
  2077. .sp
  2078. Exclude a specific application from the applications whose contents is
  2079. output. For example, to specifically exclude the \fBauth\fP application from
  2080. the output of dumpdata, you would call:
  2081. .INDENT 0.0
  2082. .INDENT 3.5
  2083. .sp
  2084. .nf
  2085. .ft C
  2086. django\-admin dumpdata \-\-exclude=auth
  2087. .ft P
  2088. .fi
  2089. .UNINDENT
  2090. .UNINDENT
  2091. .sp
  2092. If you want to exclude multiple applications, use multiple \fB\-\-exclude\fP
  2093. directives:
  2094. .INDENT 0.0
  2095. .INDENT 3.5
  2096. .sp
  2097. .nf
  2098. .ft C
  2099. django\-admin dumpdata \-\-exclude=auth \-\-exclude=contenttypes
  2100. .ft P
  2101. .fi
  2102. .UNINDENT
  2103. .UNINDENT
  2104. .INDENT 0.0
  2105. .TP
  2106. .B \-\-locale
  2107. .UNINDENT
  2108. .sp
  2109. Use the \fB\-\-locale\fP or \fB\-l\fP option to specify the locale to process.
  2110. If not provided all locales are processed.
  2111. .INDENT 0.0
  2112. .TP
  2113. .B \-\-noinput
  2114. .UNINDENT
  2115. .sp
  2116. Use the \fB\-\-noinput\fP option to suppress all user prompting, such as "Are
  2117. you sure?" confirmation messages. This is useful if \fBdjango\-admin\fP is
  2118. being executed as an unattended, automated script. You can use \fB\-\-no\-input\fP
  2119. as an alias for this option.
  2120. .sp
  2121. The \fB\-\-no\-input\fP alias was added.
  2122. .SH EXTRA NICETIES
  2123. .SS Syntax coloring
  2124. .sp
  2125. The \fBdjango\-admin\fP / \fBmanage.py\fP commands will use pretty
  2126. color\-coded output if your terminal supports ANSI\-colored output. It
  2127. won\(aqt use the color codes if you\(aqre piping the command\(aqs output to
  2128. another program.
  2129. .sp
  2130. Under Windows, the native console doesn\(aqt support ANSI escape sequences so by
  2131. default there is no color output. But you can install the \fI\%ANSICON\fP
  2132. third\-party tool, the Django commands will detect its presence and will make
  2133. use of its services to color output just like on Unix\-based platforms.
  2134. .sp
  2135. The colors used for syntax highlighting can be customized. Django
  2136. ships with three color palettes:
  2137. .INDENT 0.0
  2138. .IP \(bu 2
  2139. \fBdark\fP, suited to terminals that show white text on a black
  2140. background. This is the default palette.
  2141. .IP \(bu 2
  2142. \fBlight\fP, suited to terminals that show black text on a white
  2143. background.
  2144. .IP \(bu 2
  2145. \fBnocolor\fP, which disables syntax highlighting.
  2146. .UNINDENT
  2147. .sp
  2148. You select a palette by setting a \fBDJANGO_COLORS\fP environment
  2149. variable to specify the palette you want to use. For example, to
  2150. specify the \fBlight\fP palette under a Unix or OS/X BASH shell, you
  2151. would run the following at a command prompt:
  2152. .INDENT 0.0
  2153. .INDENT 3.5
  2154. .sp
  2155. .nf
  2156. .ft C
  2157. export DJANGO_COLORS="light"
  2158. .ft P
  2159. .fi
  2160. .UNINDENT
  2161. .UNINDENT
  2162. .sp
  2163. You can also customize the colors that are used. Django specifies a
  2164. number of roles in which color is used:
  2165. .INDENT 0.0
  2166. .IP \(bu 2
  2167. \fBerror\fP \- A major error.
  2168. .IP \(bu 2
  2169. \fBnotice\fP \- A minor error.
  2170. .IP \(bu 2
  2171. \fBsql_field\fP \- The name of a model field in SQL.
  2172. .IP \(bu 2
  2173. \fBsql_coltype\fP \- The type of a model field in SQL.
  2174. .IP \(bu 2
  2175. \fBsql_keyword\fP \- An SQL keyword.
  2176. .IP \(bu 2
  2177. \fBsql_table\fP \- The name of a model in SQL.
  2178. .IP \(bu 2
  2179. \fBhttp_info\fP \- A 1XX HTTP Informational server response.
  2180. .IP \(bu 2
  2181. \fBhttp_success\fP \- A 2XX HTTP Success server response.
  2182. .IP \(bu 2
  2183. \fBhttp_not_modified\fP \- A 304 HTTP Not Modified server response.
  2184. .IP \(bu 2
  2185. \fBhttp_redirect\fP \- A 3XX HTTP Redirect server response other than 304.
  2186. .IP \(bu 2
  2187. \fBhttp_not_found\fP \- A 404 HTTP Not Found server response.
  2188. .IP \(bu 2
  2189. \fBhttp_bad_request\fP \- A 4XX HTTP Bad Request server response other than 404.
  2190. .IP \(bu 2
  2191. \fBhttp_server_error\fP \- A 5XX HTTP Server Error response.
  2192. .UNINDENT
  2193. .sp
  2194. Each of these roles can be assigned a specific foreground and
  2195. background color, from the following list:
  2196. .INDENT 0.0
  2197. .IP \(bu 2
  2198. \fBblack\fP
  2199. .IP \(bu 2
  2200. \fBred\fP
  2201. .IP \(bu 2
  2202. \fBgreen\fP
  2203. .IP \(bu 2
  2204. \fByellow\fP
  2205. .IP \(bu 2
  2206. \fBblue\fP
  2207. .IP \(bu 2
  2208. \fBmagenta\fP
  2209. .IP \(bu 2
  2210. \fBcyan\fP
  2211. .IP \(bu 2
  2212. \fBwhite\fP
  2213. .UNINDENT
  2214. .sp
  2215. Each of these colors can then be modified by using the following
  2216. display options:
  2217. .INDENT 0.0
  2218. .IP \(bu 2
  2219. \fBbold\fP
  2220. .IP \(bu 2
  2221. \fBunderscore\fP
  2222. .IP \(bu 2
  2223. \fBblink\fP
  2224. .IP \(bu 2
  2225. \fBreverse\fP
  2226. .IP \(bu 2
  2227. \fBconceal\fP
  2228. .UNINDENT
  2229. .sp
  2230. A color specification follows one of the following patterns:
  2231. .INDENT 0.0
  2232. .IP \(bu 2
  2233. \fBrole=fg\fP
  2234. .IP \(bu 2
  2235. \fBrole=fg/bg\fP
  2236. .IP \(bu 2
  2237. \fBrole=fg,option,option\fP
  2238. .IP \(bu 2
  2239. \fBrole=fg/bg,option,option\fP
  2240. .UNINDENT
  2241. .sp
  2242. where \fBrole\fP is the name of a valid color role, \fBfg\fP is the
  2243. foreground color, \fBbg\fP is the background color and each \fBoption\fP
  2244. is one of the color modifying options. Multiple color specifications
  2245. are then separated by a semicolon. For example:
  2246. .INDENT 0.0
  2247. .INDENT 3.5
  2248. .sp
  2249. .nf
  2250. .ft C
  2251. export DJANGO_COLORS="error=yellow/blue,blink;notice=magenta"
  2252. .ft P
  2253. .fi
  2254. .UNINDENT
  2255. .UNINDENT
  2256. .sp
  2257. would specify that errors be displayed using blinking yellow on blue,
  2258. and notices displayed using magenta. All other color roles would be
  2259. left uncolored.
  2260. .sp
  2261. Colors can also be specified by extending a base palette. If you put
  2262. a palette name in a color specification, all the colors implied by that
  2263. palette will be loaded. So:
  2264. .INDENT 0.0
  2265. .INDENT 3.5
  2266. .sp
  2267. .nf
  2268. .ft C
  2269. export DJANGO_COLORS="light;error=yellow/blue,blink;notice=magenta"
  2270. .ft P
  2271. .fi
  2272. .UNINDENT
  2273. .UNINDENT
  2274. .sp
  2275. would specify the use of all the colors in the light color palette,
  2276. \fIexcept\fP for the colors for errors and notices which would be
  2277. overridden as specified.
  2278. .SS Bash completion
  2279. .sp
  2280. If you use the Bash shell, consider installing the Django bash completion
  2281. script, which lives in \fBextras/django_bash_completion\fP in the Django
  2282. distribution. It enables tab\-completion of \fBdjango\-admin\fP and
  2283. \fBmanage.py\fP commands, so you can, for instance...
  2284. .INDENT 0.0
  2285. .IP \(bu 2
  2286. Type \fBdjango\-admin\fP\&.
  2287. .IP \(bu 2
  2288. Press [TAB] to see all available options.
  2289. .IP \(bu 2
  2290. Type \fBsql\fP, then [TAB], to see all available options whose names start
  2291. with \fBsql\fP\&.
  2292. .UNINDENT
  2293. .sp
  2294. See \fB/howto/custom\-management\-commands\fP for how to add customized actions.
  2295. .INDENT 0.0
  2296. .TP
  2297. .B django.core.management.call_command(name, *args, **options)
  2298. .UNINDENT
  2299. .sp
  2300. To call a management command from code use \fBcall_command\fP\&.
  2301. .INDENT 0.0
  2302. .TP
  2303. .B \fBname\fP
  2304. the name of the command to call.
  2305. .TP
  2306. .B \fB*args\fP
  2307. a list of arguments accepted by the command.
  2308. .TP
  2309. .B \fB**options\fP
  2310. named options accepted on the command\-line.
  2311. .UNINDENT
  2312. .sp
  2313. Examples:
  2314. .INDENT 0.0
  2315. .INDENT 3.5
  2316. .sp
  2317. .nf
  2318. .ft C
  2319. from django.core import management
  2320. management.call_command(\(aqflush\(aq, verbosity=0, interactive=False)
  2321. management.call_command(\(aqloaddata\(aq, \(aqtest_data\(aq, verbosity=0)
  2322. .ft P
  2323. .fi
  2324. .UNINDENT
  2325. .UNINDENT
  2326. .sp
  2327. Note that command options that take no arguments are passed as keywords
  2328. with \fBTrue\fP or \fBFalse\fP, as you can see with the \fBinteractive\fP option above.
  2329. .sp
  2330. Named arguments can be passed by using either one of the following syntaxes:
  2331. .INDENT 0.0
  2332. .INDENT 3.5
  2333. .sp
  2334. .nf
  2335. .ft C
  2336. # Similar to the command line
  2337. management.call_command(\(aqdumpdata\(aq, \(aq\-\-natural\-foreign\(aq)
  2338. # Named argument similar to the command line minus the initial dashes and
  2339. # with internal dashes replaced by underscores
  2340. management.call_command(\(aqdumpdata\(aq, natural_foreign=True)
  2341. # \(gause_natural_foreign_keys\(ga is the option destination variable
  2342. management.call_command(\(aqdumpdata\(aq, use_natural_foreign_keys=True)
  2343. .ft P
  2344. .fi
  2345. .UNINDENT
  2346. .UNINDENT
  2347. .sp
  2348. The first syntax is now supported thanks to management commands using the
  2349. \fI\%argparse\fP module. For the second syntax, Django previously passed
  2350. the option name as\-is to the command, now it is always using the \fBdest\fP
  2351. variable name (which may or may not be the same as the option name).
  2352. .sp
  2353. Command options which take multiple options are passed a list:
  2354. .INDENT 0.0
  2355. .INDENT 3.5
  2356. .sp
  2357. .nf
  2358. .ft C
  2359. management.call_command(\(aqdumpdata\(aq, exclude=[\(aqcontenttypes\(aq, \(aqauth\(aq])
  2360. .ft P
  2361. .fi
  2362. .UNINDENT
  2363. .UNINDENT
  2364. .SH OUTPUT REDIRECTION
  2365. .sp
  2366. Note that you can redirect standard output and error streams as all commands
  2367. support the \fBstdout\fP and \fBstderr\fP options. For example, you could write:
  2368. .INDENT 0.0
  2369. .INDENT 3.5
  2370. .sp
  2371. .nf
  2372. .ft C
  2373. with open(\(aq/tmp/command_output\(aq) as f:
  2374. management.call_command(\(aqdumpdata\(aq, stdout=f)
  2375. .ft P
  2376. .fi
  2377. .UNINDENT
  2378. .UNINDENT
  2379. .SH AUTHOR
  2380. Django Software Foundation
  2381. .SH COPYRIGHT
  2382. Django Software Foundation and contributors
  2383. .\" Generated by docutils manpage writer.
  2384. .