django-admin.1 81 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976
  1. .\" Man page generated from reStructuredText.
  2. .
  3. .TH "DJANGO-ADMIN" "1" "May 17, 2022" "4.1" "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. It
  38. does the same thing as \fBdjango\-admin\fP but also sets the
  39. \fBDJANGO_SETTINGS_MODULE\fP environment variable so that it points to your
  40. project\(aqs \fBsettings.py\fP file.
  41. .sp
  42. The \fBdjango\-admin\fP script should be on your system path if you installed
  43. Django via \fBpip\fP\&. If it\(aqs not in your path, ensure you have your virtual
  44. environment activated.
  45. .sp
  46. Generally, when working on a single Django project, it\(aqs easier to use
  47. \fBmanage.py\fP than \fBdjango\-admin\fP\&. If you need to switch between multiple
  48. Django settings files, use \fBdjango\-admin\fP with
  49. \fBDJANGO_SETTINGS_MODULE\fP or the \fI\%\-\-settings\fP command line
  50. option.
  51. .sp
  52. The command\-line examples throughout this document use \fBdjango\-admin\fP to
  53. be consistent, but any example can use \fBmanage.py\fP or \fBpython \-m django\fP
  54. just as well.
  55. .SH USAGE
  56. .INDENT 0.0
  57. .INDENT 3.5
  58. .sp
  59. .nf
  60. .ft C
  61. $ django\-admin <command> [options]
  62. $ manage.py <command> [options]
  63. $ python \-m django <command> [options]
  64. .ft P
  65. .fi
  66. .UNINDENT
  67. .UNINDENT
  68. .sp
  69. \fBcommand\fP should be one of the commands listed in this document.
  70. \fBoptions\fP, which is optional, should be zero or more of the options available
  71. for the given command.
  72. .SS Getting runtime help
  73. .INDENT 0.0
  74. .TP
  75. .B django\-admin help
  76. .UNINDENT
  77. .sp
  78. Run \fBdjango\-admin help\fP to display usage information and a list of the
  79. commands provided by each application.
  80. .sp
  81. Run \fBdjango\-admin help \-\-commands\fP to display a list of all available
  82. commands.
  83. .sp
  84. Run \fBdjango\-admin help <command>\fP to display a description of the given
  85. command and a list of its available options.
  86. .SS App names
  87. .sp
  88. Many commands take a list of "app names." An "app name" is the basename of
  89. the package containing your models. For example, if your \fBINSTALLED_APPS\fP
  90. contains the string \fB\(aqmysite.blog\(aq\fP, the app name is \fBblog\fP\&.
  91. .SS Determining the version
  92. .INDENT 0.0
  93. .TP
  94. .B django\-admin version
  95. .UNINDENT
  96. .sp
  97. Run \fBdjango\-admin version\fP to display the current Django version.
  98. .sp
  99. The output follows the schema described in \fI\%PEP 440\fP:
  100. .INDENT 0.0
  101. .INDENT 3.5
  102. .sp
  103. .nf
  104. .ft C
  105. 1.4.dev17026
  106. 1.4a1
  107. 1.4
  108. .ft P
  109. .fi
  110. .UNINDENT
  111. .UNINDENT
  112. .SS Displaying debug output
  113. .sp
  114. Use \fI\%\-\-verbosity\fP, where it is supported, to specify the amount of
  115. notification and debug information that \fBdjango\-admin\fP prints to the console.
  116. .SH AVAILABLE COMMANDS
  117. .SS \fBcheck\fP
  118. .INDENT 0.0
  119. .TP
  120. .B django\-admin check [app_label [app_label ...]]
  121. .UNINDENT
  122. .sp
  123. Uses the system check framework to inspect the entire
  124. Django project for common problems.
  125. .sp
  126. By default, all apps will be checked. You can check a subset of apps by
  127. providing a list of app labels as arguments:
  128. .INDENT 0.0
  129. .INDENT 3.5
  130. .sp
  131. .nf
  132. .ft C
  133. django\-admin check auth admin myapp
  134. .ft P
  135. .fi
  136. .UNINDENT
  137. .UNINDENT
  138. .INDENT 0.0
  139. .TP
  140. .B \-\-tag TAGS, \-t TAGS
  141. .UNINDENT
  142. .sp
  143. The system check framework performs many different types of checks that are
  144. categorized with tags\&. You can use these
  145. tags to restrict the checks performed to just those in a particular category.
  146. For example, to perform only models and compatibility checks, run:
  147. .INDENT 0.0
  148. .INDENT 3.5
  149. .sp
  150. .nf
  151. .ft C
  152. django\-admin check \-\-tag models \-\-tag compatibility
  153. .ft P
  154. .fi
  155. .UNINDENT
  156. .UNINDENT
  157. .INDENT 0.0
  158. .TP
  159. .B \-\-database DATABASE
  160. .UNINDENT
  161. .sp
  162. Specifies the database to run checks requiring database access:
  163. .INDENT 0.0
  164. .INDENT 3.5
  165. .sp
  166. .nf
  167. .ft C
  168. django\-admin check \-\-database default \-\-database other
  169. .ft P
  170. .fi
  171. .UNINDENT
  172. .UNINDENT
  173. .sp
  174. By default, these checks will not be run.
  175. .INDENT 0.0
  176. .TP
  177. .B \-\-list\-tags
  178. .UNINDENT
  179. .sp
  180. Lists all available tags.
  181. .INDENT 0.0
  182. .TP
  183. .B \-\-deploy
  184. .UNINDENT
  185. .sp
  186. Activates some additional checks that are only relevant in a deployment setting.
  187. .sp
  188. You can use this option in your local development environment, but since your
  189. local development settings module may not have many of your production settings,
  190. you will probably want to point the \fBcheck\fP command at a different settings
  191. module, either by setting the \fBDJANGO_SETTINGS_MODULE\fP environment
  192. variable, or by passing the \fB\-\-settings\fP option:
  193. .INDENT 0.0
  194. .INDENT 3.5
  195. .sp
  196. .nf
  197. .ft C
  198. django\-admin check \-\-deploy \-\-settings=production_settings
  199. .ft P
  200. .fi
  201. .UNINDENT
  202. .UNINDENT
  203. .sp
  204. Or you could run it directly on a production or staging deployment to verify
  205. that the correct settings are in use (omitting \fB\-\-settings\fP). You could even
  206. make it part of your integration test suite.
  207. .INDENT 0.0
  208. .TP
  209. .B \-\-fail\-level {CRITICAL,ERROR,WARNING,INFO,DEBUG}
  210. .UNINDENT
  211. .sp
  212. Specifies the message level that will cause the command to exit with a non\-zero
  213. status. Default is \fBERROR\fP\&.
  214. .SS \fBcompilemessages\fP
  215. .INDENT 0.0
  216. .TP
  217. .B django\-admin compilemessages
  218. .UNINDENT
  219. .sp
  220. Compiles \fB\&.po\fP files created by \fI\%makemessages\fP to \fB\&.mo\fP files for
  221. use with the built\-in gettext support. See /topics/i18n/index\&.
  222. .INDENT 0.0
  223. .TP
  224. .B \-\-locale LOCALE, \-l LOCALE
  225. .UNINDENT
  226. .sp
  227. Specifies the locale(s) to process. If not provided, all locales are processed.
  228. .INDENT 0.0
  229. .TP
  230. .B \-\-exclude EXCLUDE, \-x EXCLUDE
  231. .UNINDENT
  232. .sp
  233. Specifies the locale(s) to exclude from processing. If not provided, no locales
  234. are excluded.
  235. .INDENT 0.0
  236. .TP
  237. .B \-\-use\-fuzzy, \-f
  238. .UNINDENT
  239. .sp
  240. Includes \fI\%fuzzy translations\fP into compiled files.
  241. .sp
  242. Example usage:
  243. .INDENT 0.0
  244. .INDENT 3.5
  245. .sp
  246. .nf
  247. .ft C
  248. django\-admin compilemessages \-\-locale=pt_BR
  249. django\-admin compilemessages \-\-locale=pt_BR \-\-locale=fr \-f
  250. django\-admin compilemessages \-l pt_BR
  251. django\-admin compilemessages \-l pt_BR \-l fr \-\-use\-fuzzy
  252. django\-admin compilemessages \-\-exclude=pt_BR
  253. django\-admin compilemessages \-\-exclude=pt_BR \-\-exclude=fr
  254. django\-admin compilemessages \-x pt_BR
  255. django\-admin compilemessages \-x pt_BR \-x fr
  256. .ft P
  257. .fi
  258. .UNINDENT
  259. .UNINDENT
  260. .INDENT 0.0
  261. .TP
  262. .B \-\-ignore PATTERN, \-i PATTERN
  263. .UNINDENT
  264. .sp
  265. Ignores directories matching the given \fI\%glob\fP\-style pattern. Use
  266. multiple times to ignore more.
  267. .sp
  268. Example usage:
  269. .INDENT 0.0
  270. .INDENT 3.5
  271. .sp
  272. .nf
  273. .ft C
  274. django\-admin compilemessages \-\-ignore=cache \-\-ignore=outdated/*/locale
  275. .ft P
  276. .fi
  277. .UNINDENT
  278. .UNINDENT
  279. .SS \fBcreatecachetable\fP
  280. .INDENT 0.0
  281. .TP
  282. .B django\-admin createcachetable
  283. .UNINDENT
  284. .sp
  285. Creates the cache tables for use with the database cache backend using the
  286. information from your settings file. See /topics/cache for more
  287. information.
  288. .INDENT 0.0
  289. .TP
  290. .B \-\-database DATABASE
  291. .UNINDENT
  292. .sp
  293. Specifies the database in which the cache table(s) will be created. Defaults to
  294. \fBdefault\fP\&.
  295. .INDENT 0.0
  296. .TP
  297. .B \-\-dry\-run
  298. .UNINDENT
  299. .sp
  300. Prints the SQL that would be run without actually running it, so you can
  301. customize it or use the migrations framework.
  302. .SS \fBdbshell\fP
  303. .INDENT 0.0
  304. .TP
  305. .B django\-admin dbshell
  306. .UNINDENT
  307. .sp
  308. Runs the command\-line client for the database engine specified in your
  309. \fBENGINE\fP setting, with the connection parameters
  310. specified in your \fBUSER\fP, \fBPASSWORD\fP, etc., settings.
  311. .INDENT 0.0
  312. .IP \(bu 2
  313. For PostgreSQL, this runs the \fBpsql\fP command\-line client.
  314. .IP \(bu 2
  315. For MySQL, this runs the \fBmysql\fP command\-line client.
  316. .IP \(bu 2
  317. For SQLite, this runs the \fBsqlite3\fP command\-line client.
  318. .IP \(bu 2
  319. For Oracle, this runs the \fBsqlplus\fP command\-line client.
  320. .UNINDENT
  321. .sp
  322. This command assumes the programs are on your \fBPATH\fP so that a call to
  323. the program name (\fBpsql\fP, \fBmysql\fP, \fBsqlite3\fP, \fBsqlplus\fP) will find the
  324. program in the right place. There\(aqs no way to specify the location of the
  325. program manually.
  326. .INDENT 0.0
  327. .TP
  328. .B \-\-database DATABASE
  329. .UNINDENT
  330. .sp
  331. Specifies the database onto which to open a shell. Defaults to \fBdefault\fP\&.
  332. .INDENT 0.0
  333. .TP
  334. .B \-\- ARGUMENTS
  335. .UNINDENT
  336. .sp
  337. Any arguments following a \fB\-\-\fP divider will be passed on to the underlying
  338. command\-line client. For example, with PostgreSQL you can use the \fBpsql\fP
  339. command\(aqs \fB\-c\fP flag to execute a raw SQL query directly:
  340. .INDENT 0.0
  341. .INDENT 3.5
  342. .sp
  343. .nf
  344. .ft C
  345. $ django\-admin dbshell \-\- \-c \(aqselect current_user\(aq
  346. current_user
  347. \-\-\-\-\-\-\-\-\-\-\-\-\-\-
  348. postgres
  349. (1 row)
  350. .ft P
  351. .fi
  352. .UNINDENT
  353. .UNINDENT
  354. .sp
  355. On MySQL/MariaDB, you can do this with the \fBmysql\fP command\(aqs \fB\-e\fP flag:
  356. .INDENT 0.0
  357. .INDENT 3.5
  358. .sp
  359. .nf
  360. .ft C
  361. $ django\-admin dbshell \-\- \-e "select user()"
  362. +\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+
  363. | user() |
  364. +\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+
  365. | djangonaut@localhost |
  366. +\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+
  367. .ft P
  368. .fi
  369. .UNINDENT
  370. .UNINDENT
  371. .sp
  372. \fBNOTE:\fP
  373. .INDENT 0.0
  374. .INDENT 3.5
  375. Be aware that not all options set in the \fBOPTIONS\fP part of your
  376. database configuration in \fBDATABASES\fP are passed to the
  377. command\-line client, e.g. \fB\(aqisolation_level\(aq\fP\&.
  378. .UNINDENT
  379. .UNINDENT
  380. .SS \fBdiffsettings\fP
  381. .INDENT 0.0
  382. .TP
  383. .B django\-admin diffsettings
  384. .UNINDENT
  385. .sp
  386. Displays differences between the current settings file and Django\(aqs default
  387. settings (or another settings file specified by \fI\%\-\-default\fP).
  388. .sp
  389. Settings that don\(aqt appear in the defaults are followed by \fB"###"\fP\&. For
  390. example, the default settings don\(aqt define \fBROOT_URLCONF\fP, so
  391. \fBROOT_URLCONF\fP is followed by \fB"###"\fP in the output of
  392. \fBdiffsettings\fP\&.
  393. .INDENT 0.0
  394. .TP
  395. .B \-\-all
  396. .UNINDENT
  397. .sp
  398. Displays all settings, even if they have Django\(aqs default value. Such settings
  399. are prefixed by \fB"###"\fP\&.
  400. .INDENT 0.0
  401. .TP
  402. .B \-\-default MODULE
  403. .UNINDENT
  404. .sp
  405. The settings module to compare the current settings against. Leave empty to
  406. compare against Django\(aqs default settings.
  407. .INDENT 0.0
  408. .TP
  409. .B \-\-output {hash,unified}
  410. .UNINDENT
  411. .sp
  412. Specifies the output format. Available values are \fBhash\fP and \fBunified\fP\&.
  413. \fBhash\fP is the default mode that displays the output that\(aqs described above.
  414. \fBunified\fP displays the output similar to \fBdiff \-u\fP\&. Default settings are
  415. prefixed with a minus sign, followed by the changed setting prefixed with a
  416. plus sign.
  417. .SS \fBdumpdata\fP
  418. .INDENT 0.0
  419. .TP
  420. .B django\-admin dumpdata [app_label[.ModelName] [app_label[.ModelName] ...]]
  421. .UNINDENT
  422. .sp
  423. Outputs to standard output all data in the database associated with the named
  424. application(s).
  425. .sp
  426. If no application name is provided, all installed applications will be dumped.
  427. .sp
  428. The output of \fBdumpdata\fP can be used as input for \fI\%loaddata\fP\&.
  429. .sp
  430. Note that \fBdumpdata\fP uses the default manager on the model for selecting the
  431. records to dump. If you\(aqre using a custom manager as
  432. the default manager and it filters some of the available records, not all of the
  433. objects will be dumped.
  434. .INDENT 0.0
  435. .TP
  436. .B \-\-all, \-a
  437. .UNINDENT
  438. .sp
  439. Uses Django\(aqs base manager, dumping records which might otherwise be filtered
  440. or modified by a custom manager.
  441. .INDENT 0.0
  442. .TP
  443. .B \-\-format FORMAT
  444. .UNINDENT
  445. .sp
  446. Specifies the serialization format of the output. Defaults to JSON. Supported
  447. formats are listed in serialization\-formats\&.
  448. .INDENT 0.0
  449. .TP
  450. .B \-\-indent INDENT
  451. .UNINDENT
  452. .sp
  453. Specifies the number of indentation spaces to use in the output. Defaults to
  454. \fBNone\fP which displays all data on single line.
  455. .INDENT 0.0
  456. .TP
  457. .B \-\-exclude EXCLUDE, \-e EXCLUDE
  458. .UNINDENT
  459. .sp
  460. Prevents specific applications or models (specified in the form of
  461. \fBapp_label.ModelName\fP) from being dumped. If you specify a model name, then
  462. only that model will be excluded, rather than the entire application. You can
  463. also mix application names and model names.
  464. .sp
  465. If you want to exclude multiple applications, pass \fB\-\-exclude\fP more than
  466. once:
  467. .INDENT 0.0
  468. .INDENT 3.5
  469. .sp
  470. .nf
  471. .ft C
  472. django\-admin dumpdata \-\-exclude=auth \-\-exclude=contenttypes
  473. .ft P
  474. .fi
  475. .UNINDENT
  476. .UNINDENT
  477. .INDENT 0.0
  478. .TP
  479. .B \-\-database DATABASE
  480. .UNINDENT
  481. .sp
  482. Specifies the database from which data will be dumped. Defaults to \fBdefault\fP\&.
  483. .INDENT 0.0
  484. .TP
  485. .B \-\-natural\-foreign
  486. .UNINDENT
  487. .sp
  488. Uses the \fBnatural_key()\fP model method to serialize any foreign key and
  489. many\-to\-many relationship to objects of the type that defines the method. If
  490. you\(aqre dumping \fBcontrib.auth\fP \fBPermission\fP objects or
  491. \fBcontrib.contenttypes\fP \fBContentType\fP objects, you should probably use this
  492. flag. See the natural keys
  493. documentation for more details on this and the next option.
  494. .INDENT 0.0
  495. .TP
  496. .B \-\-natural\-primary
  497. .UNINDENT
  498. .sp
  499. Omits the primary key in the serialized data of this object since it can be
  500. calculated during deserialization.
  501. .INDENT 0.0
  502. .TP
  503. .B \-\-pks PRIMARY_KEYS
  504. .UNINDENT
  505. .sp
  506. Outputs only the objects specified by a comma separated list of primary keys.
  507. This is only available when dumping one model. By default, all the records of
  508. the model are output.
  509. .INDENT 0.0
  510. .TP
  511. .B \-\-output OUTPUT, \-o OUTPUT
  512. .UNINDENT
  513. .sp
  514. Specifies a file to write the serialized data to. By default, the data goes to
  515. standard output.
  516. .sp
  517. When this option is set and \fB\-\-verbosity\fP is greater than 0 (the default), a
  518. progress bar is shown in the terminal.
  519. .SS Fixtures compression
  520. .sp
  521. The output file can be compressed with one of the \fBbz2\fP, \fBgz\fP, \fBlzma\fP, or
  522. \fBxz\fP formats by ending the filename with the corresponding extension.
  523. For example, to output the data as a compressed JSON file:
  524. .INDENT 0.0
  525. .INDENT 3.5
  526. .sp
  527. .nf
  528. .ft C
  529. django\-admin dumpdata \-o mydata.json.gz
  530. .ft P
  531. .fi
  532. .UNINDENT
  533. .UNINDENT
  534. .SS \fBflush\fP
  535. .INDENT 0.0
  536. .TP
  537. .B django\-admin flush
  538. .UNINDENT
  539. .sp
  540. Removes all data from the database and re\-executes any post\-synchronization
  541. handlers. The table of which migrations have been applied is not cleared.
  542. .sp
  543. If you would rather start from an empty database and rerun all migrations, you
  544. should drop and recreate the database and then run \fI\%migrate\fP instead.
  545. .INDENT 0.0
  546. .TP
  547. .B \-\-noinput, \-\-no\-input
  548. .UNINDENT
  549. .sp
  550. Suppresses all user prompts.
  551. .INDENT 0.0
  552. .TP
  553. .B \-\-database DATABASE
  554. .UNINDENT
  555. .sp
  556. Specifies the database to flush. Defaults to \fBdefault\fP\&.
  557. .SS \fBinspectdb\fP
  558. .INDENT 0.0
  559. .TP
  560. .B django\-admin inspectdb [table [table ...]]
  561. .UNINDENT
  562. .sp
  563. Introspects the database tables in the database pointed\-to by the
  564. \fBNAME\fP setting and outputs a Django model module (a \fBmodels.py\fP
  565. file) to standard output.
  566. .sp
  567. You may choose what tables or views to inspect by passing their names as
  568. arguments. If no arguments are provided, models are created for views only if
  569. the \fI\%\-\-include\-views\fP option is used. Models for partition tables are
  570. created on PostgreSQL if the \fI\%\-\-include\-partitions\fP option is used.
  571. .sp
  572. Use this if you have a legacy database with which you\(aqd like to use Django.
  573. The script will inspect the database and create a model for each table within
  574. it.
  575. .sp
  576. As you might expect, the created models will have an attribute for every field
  577. in the table. Note that \fBinspectdb\fP has a few special cases in its field\-name
  578. output:
  579. .INDENT 0.0
  580. .IP \(bu 2
  581. If \fBinspectdb\fP cannot map a column\(aqs type to a model field type, it\(aqll
  582. use \fBTextField\fP and will insert the Python comment
  583. \fB\(aqThis field type is a guess.\(aq\fP next to the field in the generated
  584. model. The recognized fields may depend on apps listed in
  585. \fBINSTALLED_APPS\fP\&. For example, \fBdjango.contrib.postgres\fP adds
  586. recognition for several PostgreSQL\-specific field types.
  587. .IP \(bu 2
  588. If the database column name is a Python reserved word (such as
  589. \fB\(aqpass\(aq\fP, \fB\(aqclass\(aq\fP or \fB\(aqfor\(aq\fP), \fBinspectdb\fP will append
  590. \fB\(aq_field\(aq\fP to the attribute name. For example, if a table has a column
  591. \fB\(aqfor\(aq\fP, the generated model will have a field \fB\(aqfor_field\(aq\fP, with
  592. the \fBdb_column\fP attribute set to \fB\(aqfor\(aq\fP\&. \fBinspectdb\fP will insert
  593. the Python comment
  594. \fB\(aqField renamed because it was a Python reserved word.\(aq\fP next to the
  595. field.
  596. .UNINDENT
  597. .sp
  598. This feature is meant as a shortcut, not as definitive model generation. After
  599. you run it, you\(aqll want to look over the generated models yourself to make
  600. customizations. In particular, you\(aqll need to rearrange models\(aq order, so that
  601. models that refer to other models are ordered properly.
  602. .sp
  603. Django doesn\(aqt create database defaults when a
  604. \fBdefault\fP is specified on a model field.
  605. Similarly, database defaults aren\(aqt translated to model field defaults or
  606. detected in any fashion by \fBinspectdb\fP\&.
  607. .sp
  608. By default, \fBinspectdb\fP creates unmanaged models. That is, \fBmanaged = False\fP
  609. in the model\(aqs \fBMeta\fP class tells Django not to manage each table\(aqs creation,
  610. modification, and deletion. If you do want to allow Django to manage the
  611. table\(aqs lifecycle, you\(aqll need to change the
  612. \fBmanaged\fP option to \fBTrue\fP (or remove
  613. it because \fBTrue\fP is its default value).
  614. .SS Database\-specific notes
  615. .SS Oracle
  616. .INDENT 0.0
  617. .IP \(bu 2
  618. Models are created for materialized views if \fI\%\-\-include\-views\fP is
  619. used.
  620. .UNINDENT
  621. .SS PostgreSQL
  622. .INDENT 0.0
  623. .IP \(bu 2
  624. Models are created for foreign tables.
  625. .IP \(bu 2
  626. Models are created for materialized views if
  627. \fI\%\-\-include\-views\fP is used.
  628. .IP \(bu 2
  629. Models are created for partition tables if
  630. \fI\%\-\-include\-partitions\fP is used.
  631. .UNINDENT
  632. .INDENT 0.0
  633. .TP
  634. .B \-\-database DATABASE
  635. .UNINDENT
  636. .sp
  637. Specifies the database to introspect. Defaults to \fBdefault\fP\&.
  638. .INDENT 0.0
  639. .TP
  640. .B \-\-include\-partitions
  641. .UNINDENT
  642. .sp
  643. If this option is provided, models are also created for partitions.
  644. .sp
  645. Only support for PostgreSQL is implemented.
  646. .INDENT 0.0
  647. .TP
  648. .B \-\-include\-views
  649. .UNINDENT
  650. .sp
  651. If this option is provided, models are also created for database views.
  652. .SS \fBloaddata\fP
  653. .INDENT 0.0
  654. .TP
  655. .B django\-admin loaddata fixture [fixture ...]
  656. .UNINDENT
  657. .sp
  658. Searches for and loads the contents of the named fixture into the database.
  659. .INDENT 0.0
  660. .TP
  661. .B \-\-database DATABASE
  662. .UNINDENT
  663. .sp
  664. Specifies the database into which the data will be loaded. Defaults to
  665. \fBdefault\fP\&.
  666. .INDENT 0.0
  667. .TP
  668. .B \-\-ignorenonexistent, \-i
  669. .UNINDENT
  670. .sp
  671. Ignores fields and models that may have been removed since the fixture was
  672. originally generated.
  673. .INDENT 0.0
  674. .TP
  675. .B \-\-app APP_LABEL
  676. .UNINDENT
  677. .sp
  678. Specifies a single app to look for fixtures in rather than looking in all apps.
  679. .INDENT 0.0
  680. .TP
  681. .B \-\-format FORMAT
  682. .UNINDENT
  683. .sp
  684. Specifies the serialization format (e.g.,
  685. \fBjson\fP or \fBxml\fP) for fixtures \fI\%read from stdin\fP\&.
  686. .INDENT 0.0
  687. .TP
  688. .B \-\-exclude EXCLUDE, \-e EXCLUDE
  689. .UNINDENT
  690. .sp
  691. Excludes loading the fixtures from the given applications and/or models (in the
  692. form of \fBapp_label\fP or \fBapp_label.ModelName\fP). Use the option multiple
  693. times to exclude more than one app or model.
  694. .SS What\(aqs a "fixture"?
  695. .sp
  696. A \fIfixture\fP is a collection of files that contain the serialized contents of
  697. the database. Each fixture has a unique name, and the files that comprise the
  698. fixture can be distributed over multiple directories, in multiple applications.
  699. .sp
  700. Django will search in three locations for fixtures:
  701. .INDENT 0.0
  702. .IP 1. 3
  703. In the \fBfixtures\fP directory of every installed application
  704. .IP 2. 3
  705. In any directory named in the \fBFIXTURE_DIRS\fP setting
  706. .IP 3. 3
  707. In the literal path named by the fixture
  708. .UNINDENT
  709. .sp
  710. Django will load any and all fixtures it finds in these locations that match
  711. the provided fixture names.
  712. .sp
  713. If the named fixture has a file extension, only fixtures of that type
  714. will be loaded. For example:
  715. .INDENT 0.0
  716. .INDENT 3.5
  717. .sp
  718. .nf
  719. .ft C
  720. django\-admin loaddata mydata.json
  721. .ft P
  722. .fi
  723. .UNINDENT
  724. .UNINDENT
  725. .sp
  726. would only load JSON fixtures called \fBmydata\fP\&. The fixture extension
  727. must correspond to the registered name of a
  728. serializer (e.g., \fBjson\fP or \fBxml\fP).
  729. .sp
  730. If you omit the extensions, Django will search all available fixture types
  731. for a matching fixture. For example:
  732. .INDENT 0.0
  733. .INDENT 3.5
  734. .sp
  735. .nf
  736. .ft C
  737. django\-admin loaddata mydata
  738. .ft P
  739. .fi
  740. .UNINDENT
  741. .UNINDENT
  742. .sp
  743. would look for any fixture of any fixture type called \fBmydata\fP\&. If a fixture
  744. directory contained \fBmydata.json\fP, that fixture would be loaded
  745. as a JSON fixture.
  746. .sp
  747. The fixtures that are named can include directory components. These
  748. directories will be included in the search path. For example:
  749. .INDENT 0.0
  750. .INDENT 3.5
  751. .sp
  752. .nf
  753. .ft C
  754. django\-admin loaddata foo/bar/mydata.json
  755. .ft P
  756. .fi
  757. .UNINDENT
  758. .UNINDENT
  759. .sp
  760. would search \fB<app_label>/fixtures/foo/bar/mydata.json\fP for each installed
  761. application, \fB<dirname>/foo/bar/mydata.json\fP for each directory in
  762. \fBFIXTURE_DIRS\fP, and the literal path \fBfoo/bar/mydata.json\fP\&.
  763. .sp
  764. When fixture files are processed, the data is saved to the database as is.
  765. Model defined \fBsave()\fP methods are not called, and
  766. any \fBpre_save\fP or
  767. \fBpost_save\fP signals will be called with
  768. \fBraw=True\fP since the instance only contains attributes that are local to the
  769. model. You may, for example, want to disable handlers that access
  770. related fields that aren\(aqt present during fixture loading and would otherwise
  771. raise an exception:
  772. .INDENT 0.0
  773. .INDENT 3.5
  774. .sp
  775. .nf
  776. .ft C
  777. from django.db.models.signals import post_save
  778. from .models import MyModel
  779. def my_handler(**kwargs):
  780. # disable the handler during fixture loading
  781. if kwargs[\(aqraw\(aq]:
  782. return
  783. ...
  784. post_save.connect(my_handler, sender=MyModel)
  785. .ft P
  786. .fi
  787. .UNINDENT
  788. .UNINDENT
  789. .sp
  790. You could also write a decorator to encapsulate this logic:
  791. .INDENT 0.0
  792. .INDENT 3.5
  793. .sp
  794. .nf
  795. .ft C
  796. from functools import wraps
  797. def disable_for_loaddata(signal_handler):
  798. """
  799. Decorator that turns off signal handlers when loading fixture data.
  800. """
  801. @wraps(signal_handler)
  802. def wrapper(*args, **kwargs):
  803. if kwargs[\(aqraw\(aq]:
  804. return
  805. signal_handler(*args, **kwargs)
  806. return wrapper
  807. @disable_for_loaddata
  808. def my_handler(**kwargs):
  809. ...
  810. .ft P
  811. .fi
  812. .UNINDENT
  813. .UNINDENT
  814. .sp
  815. Just be aware that this logic will disable the signals whenever fixtures are
  816. deserialized, not just during \fBloaddata\fP\&.
  817. .sp
  818. Note that the order in which fixture files are processed is undefined. However,
  819. all fixture data is installed as a single transaction, so data in
  820. one fixture can reference data in another fixture. If the database backend
  821. supports row\-level constraints, these constraints will be checked at the
  822. end of the transaction.
  823. .sp
  824. The \fI\%dumpdata\fP command can be used to generate input for \fBloaddata\fP\&.
  825. .SS Compressed fixtures
  826. .sp
  827. Fixtures may be compressed in \fBzip\fP, \fBgz\fP, \fBbz2\fP, \fBlzma\fP, or \fBxz\fP
  828. format. For example:
  829. .INDENT 0.0
  830. .INDENT 3.5
  831. .sp
  832. .nf
  833. .ft C
  834. django\-admin loaddata mydata.json
  835. .ft P
  836. .fi
  837. .UNINDENT
  838. .UNINDENT
  839. .sp
  840. would look for any of \fBmydata.json\fP, \fBmydata.json.zip\fP, \fBmydata.json.gz\fP,
  841. \fBmydata.json.bz2\fP, \fBmydata.json.lzma\fP, or \fBmydata.json.xz\fP\&. The first
  842. file contained within a compressed archive is used.
  843. .sp
  844. Note that if two fixtures with the same name but different
  845. fixture type are discovered (for example, if \fBmydata.json\fP and
  846. \fBmydata.xml.gz\fP were found in the same fixture directory), fixture
  847. installation will be aborted, and any data installed in the call to
  848. \fBloaddata\fP will be removed from the database.
  849. .INDENT 0.0
  850. .INDENT 3.5
  851. .IP "MySQL with MyISAM and fixtures"
  852. .sp
  853. The MyISAM storage engine of MySQL doesn\(aqt support transactions or
  854. constraints, so if you use MyISAM, you won\(aqt get validation of fixture
  855. data, or a rollback if multiple transaction files are found.
  856. .UNINDENT
  857. .UNINDENT
  858. .SS Database\-specific fixtures
  859. .sp
  860. If you\(aqre in a multi\-database setup, you might have fixture data that
  861. you want to load onto one database, but not onto another. In this
  862. situation, you can add a database identifier into the names of your fixtures.
  863. .sp
  864. For example, if your \fBDATABASES\fP setting has a \(aqusers\(aq database
  865. defined, name the fixture \fBmydata.users.json\fP or
  866. \fBmydata.users.json.gz\fP and the fixture will only be loaded when you
  867. specify you want to load data into the \fBusers\fP database.
  868. .SS Loading fixtures from \fBstdin\fP
  869. .sp
  870. You can use a dash as the fixture name to load input from \fBsys.stdin\fP\&. For
  871. example:
  872. .INDENT 0.0
  873. .INDENT 3.5
  874. .sp
  875. .nf
  876. .ft C
  877. django\-admin loaddata \-\-format=json \-
  878. .ft P
  879. .fi
  880. .UNINDENT
  881. .UNINDENT
  882. .sp
  883. When reading from \fBstdin\fP, the \fI\%\-\-format\fP option
  884. is required to specify the serialization format
  885. of the input (e.g., \fBjson\fP or \fBxml\fP).
  886. .sp
  887. Loading from \fBstdin\fP is useful with standard input and output redirections.
  888. For example:
  889. .INDENT 0.0
  890. .INDENT 3.5
  891. .sp
  892. .nf
  893. .ft C
  894. django\-admin dumpdata \-\-format=json \-\-database=test app_label.ModelName | django\-admin loaddata \-\-format=json \-\-database=prod \-
  895. .ft P
  896. .fi
  897. .UNINDENT
  898. .UNINDENT
  899. .SS \fBmakemessages\fP
  900. .INDENT 0.0
  901. .TP
  902. .B django\-admin makemessages
  903. .UNINDENT
  904. .sp
  905. Runs over the entire source tree of the current directory and pulls out all
  906. strings marked for translation. It creates (or updates) a message file in the
  907. conf/locale (in the Django tree) or locale (for project and application)
  908. directory. After making changes to the messages files you need to compile them
  909. with \fI\%compilemessages\fP for use with the builtin gettext support. See
  910. the i18n documentation for details.
  911. .sp
  912. This command doesn\(aqt require configured settings. However, when settings aren\(aqt
  913. configured, the command can\(aqt ignore the \fBMEDIA_ROOT\fP and
  914. \fBSTATIC_ROOT\fP directories or include \fBLOCALE_PATHS\fP\&.
  915. .INDENT 0.0
  916. .TP
  917. .B \-\-all, \-a
  918. .UNINDENT
  919. .sp
  920. Updates the message files for all available languages.
  921. .INDENT 0.0
  922. .TP
  923. .B \-\-extension EXTENSIONS, \-e EXTENSIONS
  924. .UNINDENT
  925. .sp
  926. Specifies a list of file extensions to examine (default: \fBhtml\fP, \fBtxt\fP,
  927. \fBpy\fP or \fBjs\fP if \fI\%\-\-domain\fP is \fBjs\fP).
  928. .sp
  929. Example usage:
  930. .INDENT 0.0
  931. .INDENT 3.5
  932. .sp
  933. .nf
  934. .ft C
  935. django\-admin makemessages \-\-locale=de \-\-extension xhtml
  936. .ft P
  937. .fi
  938. .UNINDENT
  939. .UNINDENT
  940. .sp
  941. Separate multiple extensions with commas or use \fB\-e\fP or \fB\-\-extension\fP
  942. multiple times:
  943. .INDENT 0.0
  944. .INDENT 3.5
  945. .sp
  946. .nf
  947. .ft C
  948. django\-admin makemessages \-\-locale=de \-\-extension=html,txt \-\-extension xml
  949. .ft P
  950. .fi
  951. .UNINDENT
  952. .UNINDENT
  953. .INDENT 0.0
  954. .TP
  955. .B \-\-locale LOCALE, \-l LOCALE
  956. .UNINDENT
  957. .sp
  958. Specifies the locale(s) to process.
  959. .INDENT 0.0
  960. .TP
  961. .B \-\-exclude EXCLUDE, \-x EXCLUDE
  962. .UNINDENT
  963. .sp
  964. Specifies the locale(s) to exclude from processing. If not provided, no locales
  965. are excluded.
  966. .sp
  967. Example usage:
  968. .INDENT 0.0
  969. .INDENT 3.5
  970. .sp
  971. .nf
  972. .ft C
  973. django\-admin makemessages \-\-locale=pt_BR
  974. django\-admin makemessages \-\-locale=pt_BR \-\-locale=fr
  975. django\-admin makemessages \-l pt_BR
  976. django\-admin makemessages \-l pt_BR \-l fr
  977. django\-admin makemessages \-\-exclude=pt_BR
  978. django\-admin makemessages \-\-exclude=pt_BR \-\-exclude=fr
  979. django\-admin makemessages \-x pt_BR
  980. django\-admin makemessages \-x pt_BR \-x fr
  981. .ft P
  982. .fi
  983. .UNINDENT
  984. .UNINDENT
  985. .INDENT 0.0
  986. .TP
  987. .B \-\-domain DOMAIN, \-d DOMAIN
  988. .UNINDENT
  989. .sp
  990. Specifies the domain of the messages files. Supported options are:
  991. .INDENT 0.0
  992. .IP \(bu 2
  993. \fBdjango\fP for all \fB*.py\fP, \fB*.html\fP and \fB*.txt\fP files (default)
  994. .IP \(bu 2
  995. \fBdjangojs\fP for \fB*.js\fP files
  996. .UNINDENT
  997. .INDENT 0.0
  998. .TP
  999. .B \-\-symlinks, \-s
  1000. .UNINDENT
  1001. .sp
  1002. Follows symlinks to directories when looking for new translation strings.
  1003. .sp
  1004. Example usage:
  1005. .INDENT 0.0
  1006. .INDENT 3.5
  1007. .sp
  1008. .nf
  1009. .ft C
  1010. django\-admin makemessages \-\-locale=de \-\-symlinks
  1011. .ft P
  1012. .fi
  1013. .UNINDENT
  1014. .UNINDENT
  1015. .INDENT 0.0
  1016. .TP
  1017. .B \-\-ignore PATTERN, \-i PATTERN
  1018. .UNINDENT
  1019. .sp
  1020. Ignores files or directories matching the given \fI\%glob\fP\-style pattern. Use
  1021. multiple times to ignore more.
  1022. .sp
  1023. These patterns are used by default: \fB\(aqCVS\(aq\fP, \fB\(aq.*\(aq\fP, \fB\(aq*~\(aq\fP, \fB\(aq*.pyc\(aq\fP\&.
  1024. .sp
  1025. Example usage:
  1026. .INDENT 0.0
  1027. .INDENT 3.5
  1028. .sp
  1029. .nf
  1030. .ft C
  1031. django\-admin makemessages \-\-locale=en_US \-\-ignore=apps/* \-\-ignore=secret/*.html
  1032. .ft P
  1033. .fi
  1034. .UNINDENT
  1035. .UNINDENT
  1036. .INDENT 0.0
  1037. .TP
  1038. .B \-\-no\-default\-ignore
  1039. .UNINDENT
  1040. .sp
  1041. Disables the default values of \fB\-\-ignore\fP\&.
  1042. .INDENT 0.0
  1043. .TP
  1044. .B \-\-no\-wrap
  1045. .UNINDENT
  1046. .sp
  1047. Disables breaking long message lines into several lines in language files.
  1048. .INDENT 0.0
  1049. .TP
  1050. .B \-\-no\-location
  1051. .UNINDENT
  1052. .sp
  1053. Suppresses writing \(aq\fB#: filename:line\fP’ comment lines in language files.
  1054. Using this option makes it harder for technically skilled translators to
  1055. understand each message\(aqs context.
  1056. .INDENT 0.0
  1057. .TP
  1058. .B \-\-add\-location [{full,file,never}]
  1059. .UNINDENT
  1060. .sp
  1061. Controls \fB#: filename:line\fP comment lines in language files. If the option
  1062. is:
  1063. .INDENT 0.0
  1064. .IP \(bu 2
  1065. \fBfull\fP (the default if not given): the lines include both file name and
  1066. line number.
  1067. .IP \(bu 2
  1068. \fBfile\fP: the line number is omitted.
  1069. .IP \(bu 2
  1070. \fBnever\fP: the lines are suppressed (same as \fI\%\-\-no\-location\fP).
  1071. .UNINDENT
  1072. .sp
  1073. Requires \fBgettext\fP 0.19 or newer.
  1074. .INDENT 0.0
  1075. .TP
  1076. .B \-\-keep\-pot
  1077. .UNINDENT
  1078. .sp
  1079. Prevents deleting the temporary \fB\&.pot\fP files generated before creating the
  1080. \fB\&.po\fP file. This is useful for debugging errors which may prevent the final
  1081. language files from being created.
  1082. .sp
  1083. \fBSEE ALSO:\fP
  1084. .INDENT 0.0
  1085. .INDENT 3.5
  1086. See customizing\-makemessages for instructions on how to customize
  1087. the keywords that \fI\%makemessages\fP passes to \fBxgettext\fP\&.
  1088. .UNINDENT
  1089. .UNINDENT
  1090. .SS \fBmakemigrations\fP
  1091. .INDENT 0.0
  1092. .TP
  1093. .B django\-admin makemigrations [app_label [app_label ...]]
  1094. .UNINDENT
  1095. .sp
  1096. Creates new migrations based on the changes detected to your models.
  1097. Migrations, their relationship with apps and more are covered in depth in
  1098. the migrations documentation\&.
  1099. .sp
  1100. Providing one or more app names as arguments will limit the migrations created
  1101. to the app(s) specified and any dependencies needed (the table at the other end
  1102. of a \fBForeignKey\fP, for example).
  1103. .sp
  1104. To add migrations to an app that doesn\(aqt have a \fBmigrations\fP directory, run
  1105. \fBmakemigrations\fP with the app\(aqs \fBapp_label\fP\&.
  1106. .INDENT 0.0
  1107. .TP
  1108. .B \-\-noinput, \-\-no\-input
  1109. .UNINDENT
  1110. .sp
  1111. Suppresses all user prompts. If a suppressed prompt cannot be resolved
  1112. automatically, the command will exit with error code 3.
  1113. .INDENT 0.0
  1114. .TP
  1115. .B \-\-empty
  1116. .UNINDENT
  1117. .sp
  1118. Outputs an empty migration for the specified apps, for manual editing. This is
  1119. for advanced users and should not be used unless you are familiar with the
  1120. migration format, migration operations, and the dependencies between your
  1121. migrations.
  1122. .INDENT 0.0
  1123. .TP
  1124. .B \-\-dry\-run
  1125. .UNINDENT
  1126. .sp
  1127. Shows what migrations would be made without actually writing any migrations
  1128. files to disk. Using this option along with \fB\-\-verbosity 3\fP will also show
  1129. the complete migrations files that would be written.
  1130. .INDENT 0.0
  1131. .TP
  1132. .B \-\-merge
  1133. .UNINDENT
  1134. .sp
  1135. Enables fixing of migration conflicts.
  1136. .INDENT 0.0
  1137. .TP
  1138. .B \-\-name NAME, \-n NAME
  1139. .UNINDENT
  1140. .sp
  1141. Allows naming the generated migration(s) instead of using a generated name. The
  1142. name must be a valid Python \fI\%identifier\fP\&.
  1143. .INDENT 0.0
  1144. .TP
  1145. .B \-\-no\-header
  1146. .UNINDENT
  1147. .sp
  1148. Generate migration files without Django version and timestamp header.
  1149. .INDENT 0.0
  1150. .TP
  1151. .B \-\-check
  1152. .UNINDENT
  1153. .sp
  1154. Makes \fBmakemigrations\fP exit with a non\-zero status when model changes without
  1155. migrations are detected.
  1156. .INDENT 0.0
  1157. .TP
  1158. .B \-\-scriptable
  1159. .UNINDENT
  1160. .sp
  1161. .sp
  1162. Diverts log output and input prompts to \fBstderr\fP, writing only paths of
  1163. generated migration files to \fBstdout\fP\&.
  1164. .SS \fBmigrate\fP
  1165. .INDENT 0.0
  1166. .TP
  1167. .B django\-admin migrate [app_label] [migration_name]
  1168. .UNINDENT
  1169. .sp
  1170. Synchronizes the database state with the current set of models and migrations.
  1171. Migrations, their relationship with apps and more are covered in depth in
  1172. the migrations documentation\&.
  1173. .sp
  1174. The behavior of this command changes depending on the arguments provided:
  1175. .INDENT 0.0
  1176. .IP \(bu 2
  1177. No arguments: All apps have all of their migrations run.
  1178. .IP \(bu 2
  1179. \fB<app_label>\fP: The specified app has its migrations run, up to the most
  1180. recent migration. This may involve running other apps\(aq migrations too, due
  1181. to dependencies.
  1182. .IP \(bu 2
  1183. \fB<app_label> <migrationname>\fP: Brings the database schema to a state where
  1184. the named migration is applied, but no later migrations in the same app are
  1185. applied. This may involve unapplying migrations if you have previously
  1186. migrated past the named migration. You can use a prefix of the migration
  1187. name, e.g. \fB0001\fP, as long as it\(aqs unique for the given app name. Use the
  1188. name \fBzero\fP to migrate all the way back i.e. to revert all applied
  1189. migrations for an app.
  1190. .UNINDENT
  1191. .sp
  1192. \fBWARNING:\fP
  1193. .INDENT 0.0
  1194. .INDENT 3.5
  1195. When unapplying migrations, all dependent migrations will also be
  1196. unapplied, regardless of \fB<app_label>\fP\&. You can use \fB\-\-plan\fP to check
  1197. which migrations will be unapplied.
  1198. .UNINDENT
  1199. .UNINDENT
  1200. .INDENT 0.0
  1201. .TP
  1202. .B \-\-database DATABASE
  1203. .UNINDENT
  1204. .sp
  1205. Specifies the database to migrate. Defaults to \fBdefault\fP\&.
  1206. .INDENT 0.0
  1207. .TP
  1208. .B \-\-fake
  1209. .UNINDENT
  1210. .sp
  1211. Marks the migrations up to the target one (following the rules above) as
  1212. applied, but without actually running the SQL to change your database schema.
  1213. .sp
  1214. This is intended for advanced users to manipulate the
  1215. current migration state directly if they\(aqre manually applying changes;
  1216. be warned that using \fB\-\-fake\fP runs the risk of putting the migration state
  1217. table into a state where manual recovery will be needed to make migrations
  1218. run correctly.
  1219. .INDENT 0.0
  1220. .TP
  1221. .B \-\-fake\-initial
  1222. .UNINDENT
  1223. .sp
  1224. Allows Django to skip an app\(aqs initial migration if all database tables with
  1225. the names of all models created by all
  1226. \fBCreateModel\fP operations in that
  1227. migration already exist. This option is intended for use when first running
  1228. migrations against a database that preexisted the use of migrations. This
  1229. option does not, however, check for matching database schema beyond matching
  1230. table names and so is only safe to use if you are confident that your existing
  1231. schema matches what is recorded in your initial migration.
  1232. .INDENT 0.0
  1233. .TP
  1234. .B \-\-plan
  1235. .UNINDENT
  1236. .sp
  1237. Shows the migration operations that will be performed for the given \fBmigrate\fP
  1238. command.
  1239. .INDENT 0.0
  1240. .TP
  1241. .B \-\-run\-syncdb
  1242. .UNINDENT
  1243. .sp
  1244. Allows creating tables for apps without migrations. While this isn\(aqt
  1245. recommended, the migrations framework is sometimes too slow on large projects
  1246. with hundreds of models.
  1247. .INDENT 0.0
  1248. .TP
  1249. .B \-\-noinput, \-\-no\-input
  1250. .UNINDENT
  1251. .sp
  1252. Suppresses all user prompts. An example prompt is asking about removing stale
  1253. content types.
  1254. .INDENT 0.0
  1255. .TP
  1256. .B \-\-check
  1257. .UNINDENT
  1258. .sp
  1259. Makes \fBmigrate\fP exit with a non\-zero status when unapplied migrations are
  1260. detected.
  1261. .INDENT 0.0
  1262. .TP
  1263. .B \-\-prune
  1264. .UNINDENT
  1265. .sp
  1266. .sp
  1267. Deletes nonexistent migrations from the \fBdjango_migrations\fP table. This is
  1268. useful when migration files replaced by a squashed migration have been removed.
  1269. See migration\-squashing for more details.
  1270. .SS \fBoptimizemigration\fP
  1271. .sp
  1272. .INDENT 0.0
  1273. .TP
  1274. .B django\-admin optimizemigration app_label migration_name
  1275. .UNINDENT
  1276. .sp
  1277. Optimizes the operations for the named migration and overrides the existing
  1278. file. If the migration contains functions that must be manually copied, the
  1279. command creates a new migration file suffixed with \fB_optimized\fP that is meant
  1280. to replace the named migration.
  1281. .INDENT 0.0
  1282. .TP
  1283. .B \-\-check
  1284. .UNINDENT
  1285. .sp
  1286. Makes \fBoptimizemigration\fP exit with a non\-zero status when a migration can be
  1287. optimized.
  1288. .SS \fBrunserver\fP
  1289. .INDENT 0.0
  1290. .TP
  1291. .B django\-admin runserver [addrport]
  1292. .UNINDENT
  1293. .sp
  1294. Starts a lightweight development web server on the local machine. By default,
  1295. the server runs on port 8000 on the IP address \fB127.0.0.1\fP\&. You can pass in an
  1296. IP address and port number explicitly.
  1297. .sp
  1298. If you run this script as a user with normal privileges (recommended), you
  1299. might not have access to start a port on a low port number. Low port numbers
  1300. are reserved for the superuser (root).
  1301. .sp
  1302. This server uses the WSGI application object specified by the
  1303. \fBWSGI_APPLICATION\fP setting.
  1304. .sp
  1305. DO NOT USE THIS SERVER IN A PRODUCTION SETTING. It has not gone through
  1306. security audits or performance tests. (And that\(aqs how it\(aqs gonna stay. We\(aqre in
  1307. the business of making web frameworks, not web servers, so improving this
  1308. server to be able to handle a production environment is outside the scope of
  1309. Django.)
  1310. .sp
  1311. The development server automatically reloads Python code for each request, as
  1312. needed. You don\(aqt need to restart the server for code changes to take effect.
  1313. However, some actions like adding files don\(aqt trigger a restart, so you\(aqll
  1314. have to restart the server in these cases.
  1315. .sp
  1316. If you\(aqre using Linux or MacOS and install both \fI\%pywatchman\fP and the
  1317. \fI\%Watchman\fP service, kernel signals will be used to autoreload the server
  1318. (rather than polling file modification timestamps each second). This offers
  1319. better performance on large projects, reduced response time after code changes,
  1320. more robust change detection, and a reduction in power usage. Django supports
  1321. \fBpywatchman\fP 1.2.0 and higher.
  1322. .INDENT 0.0
  1323. .INDENT 3.5
  1324. .IP "Large directories with many files may cause performance issues"
  1325. .sp
  1326. When using Watchman with a project that includes large non\-Python
  1327. directories like \fBnode_modules\fP, it\(aqs advisable to ignore this directory
  1328. for optimal performance. See the \fI\%watchman documentation\fP for information
  1329. on how to do this.
  1330. .UNINDENT
  1331. .UNINDENT
  1332. .INDENT 0.0
  1333. .INDENT 3.5
  1334. .IP "Watchman timeout"
  1335. .INDENT 0.0
  1336. .TP
  1337. .B DJANGO_WATCHMAN_TIMEOUT
  1338. .UNINDENT
  1339. .sp
  1340. The default timeout of \fBWatchman\fP client is 5 seconds. You can change it
  1341. by setting the \fI\%DJANGO_WATCHMAN_TIMEOUT\fP environment variable.
  1342. .UNINDENT
  1343. .UNINDENT
  1344. .sp
  1345. When you start the server, and each time you change Python code while the
  1346. server is running, the system check framework will check your entire Django
  1347. project for some common errors (see the \fI\%check\fP command). If any
  1348. errors are found, they will be printed to standard output. You can use the
  1349. \fB\-\-skip\-checks\fP option to skip running system checks.
  1350. .sp
  1351. You can run as many concurrent servers as you want, as long as they\(aqre on
  1352. separate ports by executing \fBdjango\-admin runserver\fP more than once.
  1353. .sp
  1354. Note that the default IP address, \fB127.0.0.1\fP, is not accessible from other
  1355. machines on your network. To make your development server viewable to other
  1356. machines on the network, use its own IP address (e.g. \fB192.168.2.1\fP) or
  1357. \fB0.0.0.0\fP or \fB::\fP (with IPv6 enabled).
  1358. .sp
  1359. You can provide an IPv6 address surrounded by brackets
  1360. (e.g. \fB[200a::1]:8000\fP). This will automatically enable IPv6 support.
  1361. .sp
  1362. A hostname containing ASCII\-only characters can also be used.
  1363. .sp
  1364. If the staticfiles contrib app is enabled
  1365. (default in new projects) the \fI\%runserver\fP command will be overridden
  1366. with its own runserver command.
  1367. .sp
  1368. Logging of each request and response of the server is sent to the
  1369. django\-server\-logger logger.
  1370. .INDENT 0.0
  1371. .TP
  1372. .B \-\-noreload
  1373. .UNINDENT
  1374. .sp
  1375. Disables the auto\-reloader. This means any Python code changes you make while
  1376. the server is running will \fInot\fP take effect if the particular Python modules
  1377. have already been loaded into memory.
  1378. .INDENT 0.0
  1379. .TP
  1380. .B \-\-nothreading
  1381. .UNINDENT
  1382. .sp
  1383. Disables use of threading in the development server. The server is
  1384. multithreaded by default.
  1385. .INDENT 0.0
  1386. .TP
  1387. .B \-\-ipv6, \-6
  1388. .UNINDENT
  1389. .sp
  1390. Uses IPv6 for the development server. This changes the default IP address from
  1391. \fB127.0.0.1\fP to \fB::1\fP\&.
  1392. .sp
  1393. Support for the \fB\-\-skip\-checks\fP option was added.
  1394. .SS Examples of using different ports and addresses
  1395. .sp
  1396. Port 8000 on IP address \fB127.0.0.1\fP:
  1397. .INDENT 0.0
  1398. .INDENT 3.5
  1399. .sp
  1400. .nf
  1401. .ft C
  1402. django\-admin runserver
  1403. .ft P
  1404. .fi
  1405. .UNINDENT
  1406. .UNINDENT
  1407. .sp
  1408. Port 8000 on IP address \fB1.2.3.4\fP:
  1409. .INDENT 0.0
  1410. .INDENT 3.5
  1411. .sp
  1412. .nf
  1413. .ft C
  1414. django\-admin runserver 1.2.3.4:8000
  1415. .ft P
  1416. .fi
  1417. .UNINDENT
  1418. .UNINDENT
  1419. .sp
  1420. Port 7000 on IP address \fB127.0.0.1\fP:
  1421. .INDENT 0.0
  1422. .INDENT 3.5
  1423. .sp
  1424. .nf
  1425. .ft C
  1426. django\-admin runserver 7000
  1427. .ft P
  1428. .fi
  1429. .UNINDENT
  1430. .UNINDENT
  1431. .sp
  1432. Port 7000 on IP address \fB1.2.3.4\fP:
  1433. .INDENT 0.0
  1434. .INDENT 3.5
  1435. .sp
  1436. .nf
  1437. .ft C
  1438. django\-admin runserver 1.2.3.4:7000
  1439. .ft P
  1440. .fi
  1441. .UNINDENT
  1442. .UNINDENT
  1443. .sp
  1444. Port 8000 on IPv6 address \fB::1\fP:
  1445. .INDENT 0.0
  1446. .INDENT 3.5
  1447. .sp
  1448. .nf
  1449. .ft C
  1450. django\-admin runserver \-6
  1451. .ft P
  1452. .fi
  1453. .UNINDENT
  1454. .UNINDENT
  1455. .sp
  1456. Port 7000 on IPv6 address \fB::1\fP:
  1457. .INDENT 0.0
  1458. .INDENT 3.5
  1459. .sp
  1460. .nf
  1461. .ft C
  1462. django\-admin runserver \-6 7000
  1463. .ft P
  1464. .fi
  1465. .UNINDENT
  1466. .UNINDENT
  1467. .sp
  1468. Port 7000 on IPv6 address \fB2001:0db8:1234:5678::9\fP:
  1469. .INDENT 0.0
  1470. .INDENT 3.5
  1471. .sp
  1472. .nf
  1473. .ft C
  1474. django\-admin runserver [2001:0db8:1234:5678::9]:7000
  1475. .ft P
  1476. .fi
  1477. .UNINDENT
  1478. .UNINDENT
  1479. .sp
  1480. Port 8000 on IPv4 address of host \fBlocalhost\fP:
  1481. .INDENT 0.0
  1482. .INDENT 3.5
  1483. .sp
  1484. .nf
  1485. .ft C
  1486. django\-admin runserver localhost:8000
  1487. .ft P
  1488. .fi
  1489. .UNINDENT
  1490. .UNINDENT
  1491. .sp
  1492. Port 8000 on IPv6 address of host \fBlocalhost\fP:
  1493. .INDENT 0.0
  1494. .INDENT 3.5
  1495. .sp
  1496. .nf
  1497. .ft C
  1498. django\-admin runserver \-6 localhost:8000
  1499. .ft P
  1500. .fi
  1501. .UNINDENT
  1502. .UNINDENT
  1503. .SS Serving static files with the development server
  1504. .sp
  1505. By default, the development server doesn\(aqt serve any static files for your site
  1506. (such as CSS files, images, things under \fBMEDIA_URL\fP and so forth). If
  1507. you want to configure Django to serve static media, read
  1508. /howto/static\-files/index\&.
  1509. .SS \fBsendtestemail\fP
  1510. .INDENT 0.0
  1511. .TP
  1512. .B django\-admin sendtestemail [email [email ...]]
  1513. .UNINDENT
  1514. .sp
  1515. Sends a test email (to confirm email sending through Django is working) to the
  1516. recipient(s) specified. For example:
  1517. .INDENT 0.0
  1518. .INDENT 3.5
  1519. .sp
  1520. .nf
  1521. .ft C
  1522. django\-admin sendtestemail foo@example.com bar@example.com
  1523. .ft P
  1524. .fi
  1525. .UNINDENT
  1526. .UNINDENT
  1527. .sp
  1528. There are a couple of options, and you may use any combination of them
  1529. together:
  1530. .INDENT 0.0
  1531. .TP
  1532. .B \-\-managers
  1533. .UNINDENT
  1534. .sp
  1535. Mails the email addresses specified in \fBMANAGERS\fP using
  1536. \fBmail_managers()\fP\&.
  1537. .INDENT 0.0
  1538. .TP
  1539. .B \-\-admins
  1540. .UNINDENT
  1541. .sp
  1542. Mails the email addresses specified in \fBADMINS\fP using
  1543. \fBmail_admins()\fP\&.
  1544. .SS \fBshell\fP
  1545. .INDENT 0.0
  1546. .TP
  1547. .B django\-admin shell
  1548. .UNINDENT
  1549. .sp
  1550. Starts the Python interactive interpreter.
  1551. .INDENT 0.0
  1552. .TP
  1553. .B \-\-interface {ipython,bpython,python}, \-i {ipython,bpython,python}
  1554. .UNINDENT
  1555. .sp
  1556. Specifies the shell to use. By default, Django will use \fI\%IPython\fP or \fI\%bpython\fP if
  1557. either is installed. If both are installed, specify which one you want like so:
  1558. .sp
  1559. IPython:
  1560. .INDENT 0.0
  1561. .INDENT 3.5
  1562. .sp
  1563. .nf
  1564. .ft C
  1565. django\-admin shell \-i ipython
  1566. .ft P
  1567. .fi
  1568. .UNINDENT
  1569. .UNINDENT
  1570. .sp
  1571. bpython:
  1572. .INDENT 0.0
  1573. .INDENT 3.5
  1574. .sp
  1575. .nf
  1576. .ft C
  1577. django\-admin shell \-i bpython
  1578. .ft P
  1579. .fi
  1580. .UNINDENT
  1581. .UNINDENT
  1582. .sp
  1583. If you have a "rich" shell installed but want to force use of the "plain"
  1584. Python interpreter, use \fBpython\fP as the interface name, like so:
  1585. .INDENT 0.0
  1586. .INDENT 3.5
  1587. .sp
  1588. .nf
  1589. .ft C
  1590. django\-admin shell \-i python
  1591. .ft P
  1592. .fi
  1593. .UNINDENT
  1594. .UNINDENT
  1595. .INDENT 0.0
  1596. .TP
  1597. .B \-\-nostartup
  1598. .UNINDENT
  1599. .sp
  1600. Disables reading the startup script for the "plain" Python interpreter. By
  1601. default, the script pointed to by the \fI\%PYTHONSTARTUP\fP environment
  1602. variable or the \fB~/.pythonrc.py\fP script is read.
  1603. .INDENT 0.0
  1604. .TP
  1605. .B \-\-command COMMAND, \-c COMMAND
  1606. .UNINDENT
  1607. .sp
  1608. Lets you pass a command as a string to execute it as Django, like so:
  1609. .INDENT 0.0
  1610. .INDENT 3.5
  1611. .sp
  1612. .nf
  1613. .ft C
  1614. django\-admin shell \-\-command="import django; print(django.__version__)"
  1615. .ft P
  1616. .fi
  1617. .UNINDENT
  1618. .UNINDENT
  1619. .sp
  1620. You can also pass code in on standard input to execute it. For example:
  1621. .INDENT 0.0
  1622. .INDENT 3.5
  1623. .sp
  1624. .nf
  1625. .ft C
  1626. $ django\-admin shell <<EOF
  1627. > import django
  1628. > print(django.__version__)
  1629. > EOF
  1630. .ft P
  1631. .fi
  1632. .UNINDENT
  1633. .UNINDENT
  1634. .sp
  1635. On Windows, the REPL is output due to implementation limits of
  1636. \fI\%select.select()\fP on that platform.
  1637. .SS \fBshowmigrations\fP
  1638. .INDENT 0.0
  1639. .TP
  1640. .B django\-admin showmigrations [app_label [app_label ...]]
  1641. .UNINDENT
  1642. .sp
  1643. Shows all migrations in a project. You can choose from one of two formats:
  1644. .INDENT 0.0
  1645. .TP
  1646. .B \-\-list, \-l
  1647. .UNINDENT
  1648. .sp
  1649. Lists all of the apps Django knows about, the migrations available for each
  1650. app, and whether or not each migration is applied (marked by an \fB[X]\fP next to
  1651. the migration name). For a \fB\-\-verbosity\fP of 2 and above, the applied
  1652. datetimes are also shown.
  1653. .sp
  1654. Apps without migrations are also listed, but have \fB(no migrations)\fP printed
  1655. under them.
  1656. .sp
  1657. This is the default output format.
  1658. .INDENT 0.0
  1659. .TP
  1660. .B \-\-plan, \-p
  1661. .UNINDENT
  1662. .sp
  1663. Shows the migration plan Django will follow to apply migrations. Like
  1664. \fB\-\-list\fP, applied migrations are marked by an \fB[X]\fP\&. For a \fB\-\-verbosity\fP
  1665. of 2 and above, all dependencies of a migration will also be shown.
  1666. .sp
  1667. \fBapp_label\fPs arguments limit the output, however, dependencies of provided
  1668. apps may also be included.
  1669. .INDENT 0.0
  1670. .TP
  1671. .B \-\-database DATABASE
  1672. .UNINDENT
  1673. .sp
  1674. Specifies the database to examine. Defaults to \fBdefault\fP\&.
  1675. .SS \fBsqlflush\fP
  1676. .INDENT 0.0
  1677. .TP
  1678. .B django\-admin sqlflush
  1679. .UNINDENT
  1680. .sp
  1681. Prints the SQL statements that would be executed for the \fI\%flush\fP
  1682. command.
  1683. .INDENT 0.0
  1684. .TP
  1685. .B \-\-database DATABASE
  1686. .UNINDENT
  1687. .sp
  1688. Specifies the database for which to print the SQL. Defaults to \fBdefault\fP\&.
  1689. .SS \fBsqlmigrate\fP
  1690. .INDENT 0.0
  1691. .TP
  1692. .B django\-admin sqlmigrate app_label migration_name
  1693. .UNINDENT
  1694. .sp
  1695. Prints the SQL for the named migration. This requires an active database
  1696. connection, which it will use to resolve constraint names; this means you must
  1697. generate the SQL against a copy of the database you wish to later apply it on.
  1698. .sp
  1699. Note that \fBsqlmigrate\fP doesn\(aqt colorize its output.
  1700. .INDENT 0.0
  1701. .TP
  1702. .B \-\-backwards
  1703. .UNINDENT
  1704. .sp
  1705. Generates the SQL for unapplying the migration. By default, the SQL created is
  1706. for running the migration in the forwards direction.
  1707. .INDENT 0.0
  1708. .TP
  1709. .B \-\-database DATABASE
  1710. .UNINDENT
  1711. .sp
  1712. Specifies the database for which to generate the SQL. Defaults to \fBdefault\fP\&.
  1713. .SS \fBsqlsequencereset\fP
  1714. .INDENT 0.0
  1715. .TP
  1716. .B django\-admin sqlsequencereset app_label [app_label ...]
  1717. .UNINDENT
  1718. .sp
  1719. Prints the SQL statements for resetting sequences for the given app name(s).
  1720. .sp
  1721. Sequences are indexes used by some database engines to track the next available
  1722. number for automatically incremented fields.
  1723. .sp
  1724. Use this command to generate SQL which will fix cases where a sequence is out
  1725. of sync with its automatically incremented field data.
  1726. .INDENT 0.0
  1727. .TP
  1728. .B \-\-database DATABASE
  1729. .UNINDENT
  1730. .sp
  1731. Specifies the database for which to print the SQL. Defaults to \fBdefault\fP\&.
  1732. .SS \fBsquashmigrations\fP
  1733. .INDENT 0.0
  1734. .TP
  1735. .B django\-admin squashmigrations app_label [start_migration_name] migration_name
  1736. .UNINDENT
  1737. .sp
  1738. Squashes the migrations for \fBapp_label\fP up to and including \fBmigration_name\fP
  1739. down into fewer migrations, if possible. The resulting squashed migrations
  1740. can live alongside the unsquashed ones safely. For more information,
  1741. please read migration\-squashing\&.
  1742. .sp
  1743. When \fBstart_migration_name\fP is given, Django will only include migrations
  1744. starting from and including this migration. This helps to mitigate the
  1745. squashing limitation of \fBRunPython\fP and
  1746. \fBdjango.db.migrations.operations.RunSQL\fP migration operations.
  1747. .INDENT 0.0
  1748. .TP
  1749. .B \-\-no\-optimize
  1750. .UNINDENT
  1751. .sp
  1752. Disables the optimizer when generating a squashed migration. By default, Django
  1753. will try to optimize the operations in your migrations to reduce the size of
  1754. the resulting file. Use this option if this process is failing or creating
  1755. incorrect migrations, though please also file a Django bug report about the
  1756. behavior, as optimization is meant to be safe.
  1757. .INDENT 0.0
  1758. .TP
  1759. .B \-\-noinput, \-\-no\-input
  1760. .UNINDENT
  1761. .sp
  1762. Suppresses all user prompts.
  1763. .INDENT 0.0
  1764. .TP
  1765. .B \-\-squashed\-name SQUASHED_NAME
  1766. .UNINDENT
  1767. .sp
  1768. Sets the name of the squashed migration. When omitted, the name is based on the
  1769. first and last migration, with \fB_squashed_\fP in between.
  1770. .INDENT 0.0
  1771. .TP
  1772. .B \-\-no\-header
  1773. .UNINDENT
  1774. .sp
  1775. Generate squashed migration file without Django version and timestamp header.
  1776. .SS \fBstartapp\fP
  1777. .INDENT 0.0
  1778. .TP
  1779. .B django\-admin startapp name [directory]
  1780. .UNINDENT
  1781. .sp
  1782. Creates a Django app directory structure for the given app name in the current
  1783. directory or the given destination.
  1784. .sp
  1785. By default, \fI\%the new directory\fP contains a
  1786. \fBmodels.py\fP file and other app template files. If only the app name is given,
  1787. the app directory will be created in the current working directory.
  1788. .sp
  1789. If the optional destination is provided, Django will use that existing
  1790. directory rather than creating a new one. You can use \(aq.\(aq to denote the current
  1791. working directory.
  1792. .sp
  1793. For example:
  1794. .INDENT 0.0
  1795. .INDENT 3.5
  1796. .sp
  1797. .nf
  1798. .ft C
  1799. django\-admin startapp myapp /Users/jezdez/Code/myapp
  1800. .ft P
  1801. .fi
  1802. .UNINDENT
  1803. .UNINDENT
  1804. .INDENT 0.0
  1805. .TP
  1806. .B \-\-template TEMPLATE
  1807. .UNINDENT
  1808. .sp
  1809. Provides the path to a directory with a custom app template file, or a path to
  1810. an uncompressed archive (\fB\&.tar\fP) or a compressed archive (\fB\&.tar.gz\fP,
  1811. \fB\&.tar.bz2\fP, \fB\&.tar.xz\fP, \fB\&.tar.lzma\fP, \fB\&.tgz\fP, \fB\&.tbz2\fP, \fB\&.txz\fP,
  1812. \fB\&.tlz\fP, \fB\&.zip\fP) containing the app template files.
  1813. .sp
  1814. For example, this would look for an app template in the given directory when
  1815. creating the \fBmyapp\fP app:
  1816. .INDENT 0.0
  1817. .INDENT 3.5
  1818. .sp
  1819. .nf
  1820. .ft C
  1821. django\-admin startapp \-\-template=/Users/jezdez/Code/my_app_template myapp
  1822. .ft P
  1823. .fi
  1824. .UNINDENT
  1825. .UNINDENT
  1826. .sp
  1827. Django will also accept URLs (\fBhttp\fP, \fBhttps\fP, \fBftp\fP) to compressed
  1828. archives with the app template files, downloading and extracting them on the
  1829. fly.
  1830. .sp
  1831. For example, taking advantage of GitHub\(aqs feature to expose repositories as
  1832. zip files, you can use a URL like:
  1833. .INDENT 0.0
  1834. .INDENT 3.5
  1835. .sp
  1836. .nf
  1837. .ft C
  1838. django\-admin startapp \-\-template=https://github.com/githubuser/django\-app\-template/archive/main.zip myapp
  1839. .ft P
  1840. .fi
  1841. .UNINDENT
  1842. .UNINDENT
  1843. .INDENT 0.0
  1844. .TP
  1845. .B \-\-extension EXTENSIONS, \-e EXTENSIONS
  1846. .UNINDENT
  1847. .sp
  1848. Specifies which file extensions in the app template should be rendered with the
  1849. template engine. Defaults to \fBpy\fP\&.
  1850. .INDENT 0.0
  1851. .TP
  1852. .B \-\-name FILES, \-n FILES
  1853. .UNINDENT
  1854. .sp
  1855. Specifies which files in the app template (in addition to those matching
  1856. \fB\-\-extension\fP) should be rendered with the template engine. Defaults to an
  1857. empty list.
  1858. .INDENT 0.0
  1859. .TP
  1860. .B \-\-exclude DIRECTORIES, \-x DIRECTORIES
  1861. .UNINDENT
  1862. .sp
  1863. .sp
  1864. Specifies which directories in the app template should be excluded, in addition
  1865. to \fB\&.git\fP and \fB__pycache__\fP\&. If this option is not provided, directories
  1866. named \fB__pycache__\fP or starting with \fB\&.\fP will be excluded.
  1867. .sp
  1868. The \fBtemplate context\fP used for all matching
  1869. files is:
  1870. .INDENT 0.0
  1871. .IP \(bu 2
  1872. Any option passed to the \fBstartapp\fP command (among the command\(aqs supported
  1873. options)
  1874. .IP \(bu 2
  1875. \fBapp_name\fP \-\- the app name as passed to the command
  1876. .IP \(bu 2
  1877. \fBapp_directory\fP \-\- the full path of the newly created app
  1878. .IP \(bu 2
  1879. \fBcamel_case_app_name\fP \-\- the app name in camel case format
  1880. .IP \(bu 2
  1881. \fBdocs_version\fP \-\- the version of the documentation: \fB\(aqdev\(aq\fP or \fB\(aq1.x\(aq\fP
  1882. .IP \(bu 2
  1883. \fBdjango_version\fP \-\- the version of Django, e.g. \fB\(aq2.0.3\(aq\fP
  1884. .UNINDENT
  1885. .sp
  1886. \fBWARNING:\fP
  1887. .INDENT 0.0
  1888. .INDENT 3.5
  1889. When the app template files are rendered with the Django template
  1890. engine (by default all \fB*.py\fP files), Django will also replace all
  1891. stray template variables contained. For example, if one of the Python files
  1892. contains a docstring explaining a particular feature related
  1893. to template rendering, it might result in an incorrect example.
  1894. .sp
  1895. To work around this problem, you can use the \fBtemplatetag\fP
  1896. template tag to "escape" the various parts of the template syntax.
  1897. .sp
  1898. In addition, to allow Python template files that contain Django template
  1899. language syntax while also preventing packaging systems from trying to
  1900. byte\-compile invalid \fB*.py\fP files, template files ending with \fB\&.py\-tpl\fP
  1901. will be renamed to \fB\&.py\fP\&.
  1902. .UNINDENT
  1903. .UNINDENT
  1904. .SS \fBstartproject\fP
  1905. .INDENT 0.0
  1906. .TP
  1907. .B django\-admin startproject name [directory]
  1908. .UNINDENT
  1909. .sp
  1910. Creates a Django project directory structure for the given project name in
  1911. the current directory or the given destination.
  1912. .sp
  1913. By default, \fI\%the new directory\fP contains
  1914. \fBmanage.py\fP and a project package (containing a \fBsettings.py\fP and other
  1915. files).
  1916. .sp
  1917. If only the project name is given, both the project directory and project
  1918. package will be named \fB<projectname>\fP and the project directory
  1919. will be created in the current working directory.
  1920. .sp
  1921. If the optional destination is provided, Django will use that existing
  1922. directory as the project directory, and create \fBmanage.py\fP and the project
  1923. package within it. Use \(aq.\(aq to denote the current working directory.
  1924. .sp
  1925. For example:
  1926. .INDENT 0.0
  1927. .INDENT 3.5
  1928. .sp
  1929. .nf
  1930. .ft C
  1931. django\-admin startproject myproject /Users/jezdez/Code/myproject_repo
  1932. .ft P
  1933. .fi
  1934. .UNINDENT
  1935. .UNINDENT
  1936. .INDENT 0.0
  1937. .TP
  1938. .B \-\-template TEMPLATE
  1939. .UNINDENT
  1940. .sp
  1941. Specifies a directory, file path, or URL of a custom project template. See the
  1942. \fI\%startapp \-\-template\fP documentation for examples and usage.
  1943. .INDENT 0.0
  1944. .TP
  1945. .B \-\-extension EXTENSIONS, \-e EXTENSIONS
  1946. .UNINDENT
  1947. .sp
  1948. Specifies which file extensions in the project template should be rendered with
  1949. the template engine. Defaults to \fBpy\fP\&.
  1950. .INDENT 0.0
  1951. .TP
  1952. .B \-\-name FILES, \-n FILES
  1953. .UNINDENT
  1954. .sp
  1955. Specifies which files in the project template (in addition to those matching
  1956. \fB\-\-extension\fP) should be rendered with the template engine. Defaults to an
  1957. empty list.
  1958. .INDENT 0.0
  1959. .TP
  1960. .B \-\-exclude DIRECTORIES, \-x DIRECTORIES
  1961. .UNINDENT
  1962. .sp
  1963. .sp
  1964. Specifies which directories in the project template should be excluded, in
  1965. addition to \fB\&.git\fP and \fB__pycache__\fP\&. If this option is not provided,
  1966. directories named \fB__pycache__\fP or starting with \fB\&.\fP will be excluded.
  1967. .sp
  1968. The \fBtemplate context\fP used is:
  1969. .INDENT 0.0
  1970. .IP \(bu 2
  1971. Any option passed to the \fBstartproject\fP command (among the command\(aqs
  1972. supported options)
  1973. .IP \(bu 2
  1974. \fBproject_name\fP \-\- the project name as passed to the command
  1975. .IP \(bu 2
  1976. \fBproject_directory\fP \-\- the full path of the newly created project
  1977. .IP \(bu 2
  1978. \fBsecret_key\fP \-\- a random key for the \fBSECRET_KEY\fP setting
  1979. .IP \(bu 2
  1980. \fBdocs_version\fP \-\- the version of the documentation: \fB\(aqdev\(aq\fP or \fB\(aq1.x\(aq\fP
  1981. .IP \(bu 2
  1982. \fBdjango_version\fP \-\- the version of Django, e.g. \fB\(aq2.0.3\(aq\fP
  1983. .UNINDENT
  1984. .sp
  1985. Please also see the \fI\%rendering warning\fP as mentioned
  1986. for \fI\%startapp\fP\&.
  1987. .SS \fBtest\fP
  1988. .INDENT 0.0
  1989. .TP
  1990. .B django\-admin test [test_label [test_label ...]]
  1991. .UNINDENT
  1992. .sp
  1993. Runs tests for all installed apps. See /topics/testing/index for more
  1994. information.
  1995. .INDENT 0.0
  1996. .TP
  1997. .B \-\-failfast
  1998. .UNINDENT
  1999. .sp
  2000. Stops running tests and reports the failure immediately after a test fails.
  2001. .INDENT 0.0
  2002. .TP
  2003. .B \-\-testrunner TESTRUNNER
  2004. .UNINDENT
  2005. .sp
  2006. Controls the test runner class that is used to execute tests. This value
  2007. overrides the value provided by the \fBTEST_RUNNER\fP setting.
  2008. .INDENT 0.0
  2009. .TP
  2010. .B \-\-noinput, \-\-no\-input
  2011. .UNINDENT
  2012. .sp
  2013. Suppresses all user prompts. A typical prompt is a warning about deleting an
  2014. existing test database.
  2015. .SS Test runner options
  2016. .sp
  2017. The \fBtest\fP command receives options on behalf of the specified
  2018. \fI\%\-\-testrunner\fP\&. These are the options of the default test runner:
  2019. \fBDiscoverRunner\fP\&.
  2020. .INDENT 0.0
  2021. .TP
  2022. .B \-\-keepdb
  2023. .UNINDENT
  2024. .sp
  2025. Preserves the test database between test runs. This has the advantage of
  2026. skipping both the create and destroy actions which can greatly decrease the
  2027. time to run tests, especially those in a large test suite. If the test database
  2028. does not exist, it will be created on the first run and then preserved for each
  2029. subsequent run. Unless the \fBMIGRATE\fP test setting is
  2030. \fBFalse\fP, any unapplied migrations will also be applied to the test database
  2031. before running the test suite.
  2032. .INDENT 0.0
  2033. .TP
  2034. .B \-\-shuffle [SEED]
  2035. .UNINDENT
  2036. .sp
  2037. .sp
  2038. Randomizes the order of tests before running them. This can help detect tests
  2039. that aren\(aqt properly isolated. The test order generated by this option is a
  2040. deterministic function of the integer seed given. When no seed is passed, a
  2041. seed is chosen randomly and printed to the console. To repeat a particular test
  2042. order, pass a seed. The test orders generated by this option preserve Django\(aqs
  2043. guarantees on test order\&. They also keep tests grouped
  2044. by test case class.
  2045. .sp
  2046. The shuffled orderings also have a special consistency property useful when
  2047. narrowing down isolation issues. Namely, for a given seed and when running a
  2048. subset of tests, the new order will be the original shuffling restricted to the
  2049. smaller set. Similarly, when adding tests while keeping the seed the same, the
  2050. order of the original tests will be the same in the new order.
  2051. .INDENT 0.0
  2052. .TP
  2053. .B \-\-reverse, \-r
  2054. .UNINDENT
  2055. .sp
  2056. Sorts test cases in the opposite execution order. This may help in debugging
  2057. the side effects of tests that aren\(aqt properly isolated. Grouping by test
  2058. class is preserved when using this option. This can be used
  2059. in conjunction with \fB\-\-shuffle\fP to reverse the order for a particular seed.
  2060. .INDENT 0.0
  2061. .TP
  2062. .B \-\-debug\-mode
  2063. .UNINDENT
  2064. .sp
  2065. Sets the \fBDEBUG\fP setting to \fBTrue\fP prior to running tests. This may
  2066. help troubleshoot test failures.
  2067. .INDENT 0.0
  2068. .TP
  2069. .B \-\-debug\-sql, \-d
  2070. .UNINDENT
  2071. .sp
  2072. Enables SQL logging for failing tests. If
  2073. \fB\-\-verbosity\fP is \fB2\fP, then queries in passing tests are also output.
  2074. .INDENT 0.0
  2075. .TP
  2076. .B \-\-parallel [N]
  2077. .UNINDENT
  2078. .INDENT 0.0
  2079. .TP
  2080. .B DJANGO_TEST_PROCESSES
  2081. .UNINDENT
  2082. .sp
  2083. Runs tests in separate parallel processes. Since modern processors have
  2084. multiple cores, this allows running tests significantly faster.
  2085. .sp
  2086. Using \fB\-\-parallel\fP without a value, or with the value \fBauto\fP, runs one test
  2087. process per core according to \fI\%multiprocessing.cpu_count()\fP\&. You can
  2088. override this by passing the desired number of processes, e.g.
  2089. \fB\-\-parallel 4\fP, or by setting the \fI\%DJANGO_TEST_PROCESSES\fP environment
  2090. variable.
  2091. .sp
  2092. Django distributes test cases — \fI\%unittest.TestCase\fP subclasses — to
  2093. subprocesses. If there are fewer test cases than configured processes, Django
  2094. will reduce the number of processes accordingly.
  2095. .sp
  2096. Each process gets its own database. You must ensure that different test cases
  2097. don\(aqt access the same resources. For instance, test cases that touch the
  2098. filesystem should create a temporary directory for their own use.
  2099. .sp
  2100. \fBNOTE:\fP
  2101. .INDENT 0.0
  2102. .INDENT 3.5
  2103. If you have test classes that cannot be run in parallel, you can use
  2104. \fBSerializeMixin\fP to run them sequentially. See Enforce running test
  2105. classes sequentially\&.
  2106. .UNINDENT
  2107. .UNINDENT
  2108. .sp
  2109. This option requires the third\-party \fBtblib\fP package to display tracebacks
  2110. correctly:
  2111. .INDENT 0.0
  2112. .INDENT 3.5
  2113. .sp
  2114. .nf
  2115. .ft C
  2116. $ python \-m pip install tblib
  2117. .ft P
  2118. .fi
  2119. .UNINDENT
  2120. .UNINDENT
  2121. .sp
  2122. This feature isn\(aqt available on Windows. It doesn\(aqt work with the Oracle
  2123. database backend either.
  2124. .sp
  2125. If you want to use \fI\%pdb\fP while debugging tests, you must disable parallel
  2126. execution (\fB\-\-parallel=1\fP). You\(aqll see something like \fBbdb.BdbQuit\fP if you
  2127. don\(aqt.
  2128. .sp
  2129. \fBWARNING:\fP
  2130. .INDENT 0.0
  2131. .INDENT 3.5
  2132. When test parallelization is enabled and a test fails, Django may be
  2133. unable to display the exception traceback. This can make debugging
  2134. difficult. If you encounter this problem, run the affected test without
  2135. parallelization to see the traceback of the failure.
  2136. .sp
  2137. This is a known limitation. It arises from the need to serialize objects
  2138. in order to exchange them between processes. See
  2139. \fI\%What can be pickled and unpickled?\fP for details.
  2140. .UNINDENT
  2141. .UNINDENT
  2142. .sp
  2143. Support for the value \fBauto\fP was added.
  2144. .INDENT 0.0
  2145. .TP
  2146. .B \-\-tag TAGS
  2147. .UNINDENT
  2148. .sp
  2149. Runs only tests marked with the specified tags\&.
  2150. May be specified multiple times and combined with \fI\%test \-\-exclude\-tag\fP\&.
  2151. .sp
  2152. Tests that fail to load are always considered matching.
  2153. .sp
  2154. In older versions, tests that failed to load did not match tags.
  2155. .INDENT 0.0
  2156. .TP
  2157. .B \-\-exclude\-tag EXCLUDE_TAGS
  2158. .UNINDENT
  2159. .sp
  2160. Excludes tests marked with the specified tags\&.
  2161. May be specified multiple times and combined with \fI\%test \-\-tag\fP\&.
  2162. .INDENT 0.0
  2163. .TP
  2164. .B \-k TEST_NAME_PATTERNS
  2165. .UNINDENT
  2166. .sp
  2167. Runs test methods and classes matching test name patterns, in the same way as
  2168. \fI\%unittest\(aqs \-k option\fP\&. Can be specified multiple times.
  2169. .INDENT 0.0
  2170. .TP
  2171. .B \-\-pdb
  2172. .UNINDENT
  2173. .sp
  2174. Spawns a \fBpdb\fP debugger at each test error or failure. If you have it
  2175. installed, \fBipdb\fP is used instead.
  2176. .INDENT 0.0
  2177. .TP
  2178. .B \-\-buffer, \-b
  2179. .UNINDENT
  2180. .sp
  2181. Discards output (\fBstdout\fP and \fBstderr\fP) for passing tests, in the same way
  2182. as \fI\%unittest\(aqs \-\-buffer option\fP\&.
  2183. .INDENT 0.0
  2184. .TP
  2185. .B \-\-no\-faulthandler
  2186. .UNINDENT
  2187. .sp
  2188. Django automatically calls \fI\%faulthandler.enable()\fP when starting the
  2189. tests, which allows it to print a traceback if the interpreter crashes. Pass
  2190. \fB\-\-no\-faulthandler\fP to disable this behavior.
  2191. .INDENT 0.0
  2192. .TP
  2193. .B \-\-timing
  2194. .UNINDENT
  2195. .sp
  2196. Outputs timings, including database setup and total run time.
  2197. .SS \fBtestserver\fP
  2198. .INDENT 0.0
  2199. .TP
  2200. .B django\-admin testserver [fixture [fixture ...]]
  2201. .UNINDENT
  2202. .sp
  2203. Runs a Django development server (as in \fI\%runserver\fP) using data from
  2204. the given fixture(s).
  2205. .sp
  2206. For example, this command:
  2207. .INDENT 0.0
  2208. .INDENT 3.5
  2209. .sp
  2210. .nf
  2211. .ft C
  2212. django\-admin testserver mydata.json
  2213. .ft P
  2214. .fi
  2215. .UNINDENT
  2216. .UNINDENT
  2217. .sp
  2218. \&...would perform the following steps:
  2219. .INDENT 0.0
  2220. .IP 1. 3
  2221. Create a test database, as described in the\-test\-database\&.
  2222. .IP 2. 3
  2223. Populate the test database with fixture data from the given fixtures.
  2224. (For more on fixtures, see the documentation for \fI\%loaddata\fP above.)
  2225. .IP 3. 3
  2226. Runs the Django development server (as in \fI\%runserver\fP), pointed at
  2227. this newly created test database instead of your production database.
  2228. .UNINDENT
  2229. .sp
  2230. This is useful in a number of ways:
  2231. .INDENT 0.0
  2232. .IP \(bu 2
  2233. When you\(aqre writing unit tests of how your views
  2234. act with certain fixture data, you can use \fBtestserver\fP to interact with
  2235. the views in a web browser, manually.
  2236. .IP \(bu 2
  2237. Let\(aqs say you\(aqre developing your Django application and have a "pristine"
  2238. copy of a database that you\(aqd like to interact with. You can dump your
  2239. database to a fixture (using the \fI\%dumpdata\fP command, explained
  2240. above), then use \fBtestserver\fP to run your web application with that data.
  2241. With this arrangement, you have the flexibility of messing up your data
  2242. in any way, knowing that whatever data changes you\(aqre making are only
  2243. being made to a test database.
  2244. .UNINDENT
  2245. .sp
  2246. Note that this server does \fInot\fP automatically detect changes to your Python
  2247. source code (as \fI\%runserver\fP does). It does, however, detect changes to
  2248. templates.
  2249. .INDENT 0.0
  2250. .TP
  2251. .B \-\-addrport ADDRPORT
  2252. .UNINDENT
  2253. .sp
  2254. Specifies a different port, or IP address and port, from the default of
  2255. \fB127.0.0.1:8000\fP\&. This value follows exactly the same format and serves
  2256. exactly the same function as the argument to the \fI\%runserver\fP command.
  2257. .sp
  2258. Examples:
  2259. .sp
  2260. To run the test server on port 7000 with \fBfixture1\fP and \fBfixture2\fP:
  2261. .INDENT 0.0
  2262. .INDENT 3.5
  2263. .sp
  2264. .nf
  2265. .ft C
  2266. django\-admin testserver \-\-addrport 7000 fixture1 fixture2
  2267. django\-admin testserver fixture1 fixture2 \-\-addrport 7000
  2268. .ft P
  2269. .fi
  2270. .UNINDENT
  2271. .UNINDENT
  2272. .sp
  2273. (The above statements are equivalent. We include both of them to demonstrate
  2274. that it doesn\(aqt matter whether the options come before or after the fixture
  2275. arguments.)
  2276. .sp
  2277. To run on 1.2.3.4:7000 with a \fBtest\fP fixture:
  2278. .INDENT 0.0
  2279. .INDENT 3.5
  2280. .sp
  2281. .nf
  2282. .ft C
  2283. django\-admin testserver \-\-addrport 1.2.3.4:7000 test
  2284. .ft P
  2285. .fi
  2286. .UNINDENT
  2287. .UNINDENT
  2288. .INDENT 0.0
  2289. .TP
  2290. .B \-\-noinput, \-\-no\-input
  2291. .UNINDENT
  2292. .sp
  2293. Suppresses all user prompts. A typical prompt is a warning about deleting an
  2294. existing test database.
  2295. .SH COMMANDS PROVIDED BY APPLICATIONS
  2296. .sp
  2297. Some commands are only available when the \fBdjango.contrib\fP application that
  2298. implements them has been
  2299. \fBenabled\fP\&. This section describes them grouped by
  2300. their application.
  2301. .SS \fBdjango.contrib.auth\fP
  2302. .SS \fBchangepassword\fP
  2303. .INDENT 0.0
  2304. .TP
  2305. .B django\-admin changepassword [<username>]
  2306. .UNINDENT
  2307. .sp
  2308. This command is only available if Django\(aqs authentication system (\fBdjango.contrib.auth\fP) is installed.
  2309. .sp
  2310. Allows changing a user\(aqs password. It prompts you to enter a new password twice
  2311. for the given user. If the entries are identical, this immediately becomes the
  2312. new password. If you do not supply a user, the command will attempt to change
  2313. the password whose username matches the current user.
  2314. .INDENT 0.0
  2315. .TP
  2316. .B \-\-database DATABASE
  2317. .UNINDENT
  2318. .sp
  2319. Specifies the database to query for the user. Defaults to \fBdefault\fP\&.
  2320. .sp
  2321. Example usage:
  2322. .INDENT 0.0
  2323. .INDENT 3.5
  2324. .sp
  2325. .nf
  2326. .ft C
  2327. django\-admin changepassword ringo
  2328. .ft P
  2329. .fi
  2330. .UNINDENT
  2331. .UNINDENT
  2332. .SS \fBcreatesuperuser\fP
  2333. .INDENT 0.0
  2334. .TP
  2335. .B django\-admin createsuperuser
  2336. .UNINDENT
  2337. .INDENT 0.0
  2338. .TP
  2339. .B DJANGO_SUPERUSER_PASSWORD
  2340. .UNINDENT
  2341. .sp
  2342. This command is only available if Django\(aqs authentication system (\fBdjango.contrib.auth\fP) is installed.
  2343. .sp
  2344. Creates a superuser account (a user who has all permissions). This is
  2345. useful if you need to create an initial superuser account or if you need to
  2346. programmatically generate superuser accounts for your site(s).
  2347. .sp
  2348. When run interactively, this command will prompt for a password for
  2349. the new superuser account. When run non\-interactively, you can provide
  2350. a password by setting the \fI\%DJANGO_SUPERUSER_PASSWORD\fP environment
  2351. variable. Otherwise, no password will be set, and the superuser account will
  2352. not be able to log in until a password has been manually set for it.
  2353. .sp
  2354. In non\-interactive mode, the
  2355. \fBUSERNAME_FIELD\fP and required
  2356. fields (listed in
  2357. \fBREQUIRED_FIELDS\fP) fall back to
  2358. \fBDJANGO_SUPERUSER_<uppercase_field_name>\fP environment variables, unless they
  2359. are overridden by a command line argument. For example, to provide an \fBemail\fP
  2360. field, you can use \fBDJANGO_SUPERUSER_EMAIL\fP environment variable.
  2361. .INDENT 0.0
  2362. .TP
  2363. .B \-\-noinput, \-\-no\-input
  2364. .UNINDENT
  2365. .sp
  2366. Suppresses all user prompts. If a suppressed prompt cannot be resolved
  2367. automatically, the command will exit with error code 1.
  2368. .INDENT 0.0
  2369. .TP
  2370. .B \-\-username USERNAME
  2371. .UNINDENT
  2372. .INDENT 0.0
  2373. .TP
  2374. .B \-\-email EMAIL
  2375. .UNINDENT
  2376. .sp
  2377. The username and email address for the new account can be supplied by
  2378. using the \fB\-\-username\fP and \fB\-\-email\fP arguments on the command
  2379. line. If either of those is not supplied, \fBcreatesuperuser\fP will prompt for
  2380. it when running interactively.
  2381. .INDENT 0.0
  2382. .TP
  2383. .B \-\-database DATABASE
  2384. .UNINDENT
  2385. .sp
  2386. Specifies the database into which the superuser object will be saved.
  2387. .sp
  2388. You can subclass the management command and override \fBget_input_data()\fP if you
  2389. want to customize data input and validation. Consult the source code for
  2390. details on the existing implementation and the method\(aqs parameters. For example,
  2391. it could be useful if you have a \fBForeignKey\fP in
  2392. \fBREQUIRED_FIELDS\fP and want to
  2393. allow creating an instance instead of entering the primary key of an existing
  2394. instance.
  2395. .SS \fBdjango.contrib.contenttypes\fP
  2396. .SS \fBremove_stale_contenttypes\fP
  2397. .INDENT 0.0
  2398. .TP
  2399. .B django\-admin remove_stale_contenttypes
  2400. .UNINDENT
  2401. .sp
  2402. This command is only available if Django\(aqs contenttypes app (\fBdjango.contrib.contenttypes\fP) is installed.
  2403. .sp
  2404. Deletes stale content types (from deleted models) in your database. Any objects
  2405. that depend on the deleted content types will also be deleted. A list of
  2406. deleted objects will be displayed before you confirm it\(aqs okay to proceed with
  2407. the deletion.
  2408. .INDENT 0.0
  2409. .TP
  2410. .B \-\-database DATABASE
  2411. .UNINDENT
  2412. .sp
  2413. Specifies the database to use. Defaults to \fBdefault\fP\&.
  2414. .INDENT 0.0
  2415. .TP
  2416. .B \-\-include\-stale\-apps
  2417. .UNINDENT
  2418. .sp
  2419. Deletes stale content types including ones from previously installed apps that
  2420. have been removed from \fBINSTALLED_APPS\fP\&. Defaults to \fBFalse\fP\&.
  2421. .SS \fBdjango.contrib.gis\fP
  2422. .SS \fBogrinspect\fP
  2423. .sp
  2424. This command is only available if GeoDjango
  2425. (\fBdjango.contrib.gis\fP) is installed.
  2426. .sp
  2427. Please refer to its \fBdescription\fP in the GeoDjango
  2428. documentation.
  2429. .SS \fBdjango.contrib.sessions\fP
  2430. .SS \fBclearsessions\fP
  2431. .INDENT 0.0
  2432. .TP
  2433. .B django\-admin clearsessions
  2434. .UNINDENT
  2435. .sp
  2436. Can be run as a cron job or directly to clean out expired sessions.
  2437. .SS \fBdjango.contrib.sitemaps\fP
  2438. .SS \fBping_google\fP
  2439. .sp
  2440. This command is only available if the Sitemaps framework (\fBdjango.contrib.sitemaps\fP) is installed.
  2441. .sp
  2442. Please refer to its \fBdescription\fP in the Sitemaps
  2443. documentation.
  2444. .SS \fBdjango.contrib.staticfiles\fP
  2445. .SS \fBcollectstatic\fP
  2446. .sp
  2447. This command is only available if the static files application (\fBdjango.contrib.staticfiles\fP) is installed.
  2448. .sp
  2449. Please refer to its \fBdescription\fP in the
  2450. staticfiles documentation.
  2451. .SS \fBfindstatic\fP
  2452. .sp
  2453. This command is only available if the static files application (\fBdjango.contrib.staticfiles\fP) is installed.
  2454. .sp
  2455. Please refer to its \fBdescription\fP in the staticfiles documentation.
  2456. .SH DEFAULT OPTIONS
  2457. .sp
  2458. Although some commands may allow their own custom options, every command
  2459. allows for the following options by default:
  2460. .INDENT 0.0
  2461. .TP
  2462. .B \-\-pythonpath PYTHONPATH
  2463. .UNINDENT
  2464. .sp
  2465. Adds the given filesystem path to the Python \fI\%import search path\fP\&. If this
  2466. isn\(aqt provided, \fBdjango\-admin\fP will use the \fI\%PYTHONPATH\fP environment
  2467. variable.
  2468. .sp
  2469. This option is unnecessary in \fBmanage.py\fP, because it takes care of setting
  2470. the Python path for you.
  2471. .sp
  2472. Example usage:
  2473. .INDENT 0.0
  2474. .INDENT 3.5
  2475. .sp
  2476. .nf
  2477. .ft C
  2478. django\-admin migrate \-\-pythonpath=\(aq/home/djangoprojects/myproject\(aq
  2479. .ft P
  2480. .fi
  2481. .UNINDENT
  2482. .UNINDENT
  2483. .INDENT 0.0
  2484. .TP
  2485. .B \-\-settings SETTINGS
  2486. .UNINDENT
  2487. .sp
  2488. Specifies the settings module to use. The settings module should be in Python
  2489. package syntax, e.g. \fBmysite.settings\fP\&. If this isn\(aqt provided,
  2490. \fBdjango\-admin\fP will use the \fBDJANGO_SETTINGS_MODULE\fP environment
  2491. variable.
  2492. .sp
  2493. This option is unnecessary in \fBmanage.py\fP, because it uses
  2494. \fBsettings.py\fP from the current project by default.
  2495. .sp
  2496. Example usage:
  2497. .INDENT 0.0
  2498. .INDENT 3.5
  2499. .sp
  2500. .nf
  2501. .ft C
  2502. django\-admin migrate \-\-settings=mysite.settings
  2503. .ft P
  2504. .fi
  2505. .UNINDENT
  2506. .UNINDENT
  2507. .INDENT 0.0
  2508. .TP
  2509. .B \-\-traceback
  2510. .UNINDENT
  2511. .sp
  2512. Displays a full stack trace when a \fBCommandError\fP
  2513. is raised. By default, \fBdjango\-admin\fP will show an error message when a
  2514. \fBCommandError\fP occurs and a full stack trace for any other exception.
  2515. .sp
  2516. This option is ignored by \fI\%runserver\fP\&.
  2517. .sp
  2518. Example usage:
  2519. .INDENT 0.0
  2520. .INDENT 3.5
  2521. .sp
  2522. .nf
  2523. .ft C
  2524. django\-admin migrate \-\-traceback
  2525. .ft P
  2526. .fi
  2527. .UNINDENT
  2528. .UNINDENT
  2529. .INDENT 0.0
  2530. .TP
  2531. .B \-\-verbosity {0,1,2,3}, \-v {0,1,2,3}
  2532. .UNINDENT
  2533. .sp
  2534. Specifies the amount of notification and debug information that a command
  2535. should print to the console.
  2536. .INDENT 0.0
  2537. .IP \(bu 2
  2538. \fB0\fP means no output.
  2539. .IP \(bu 2
  2540. \fB1\fP means normal output (default).
  2541. .IP \(bu 2
  2542. \fB2\fP means verbose output.
  2543. .IP \(bu 2
  2544. \fB3\fP means \fIvery\fP verbose output.
  2545. .UNINDENT
  2546. .sp
  2547. This option is ignored by \fI\%runserver\fP\&.
  2548. .sp
  2549. Example usage:
  2550. .INDENT 0.0
  2551. .INDENT 3.5
  2552. .sp
  2553. .nf
  2554. .ft C
  2555. django\-admin migrate \-\-verbosity 2
  2556. .ft P
  2557. .fi
  2558. .UNINDENT
  2559. .UNINDENT
  2560. .INDENT 0.0
  2561. .TP
  2562. .B \-\-no\-color
  2563. .UNINDENT
  2564. .sp
  2565. Disables colorized command output. Some commands format their output to be
  2566. colorized. For example, errors will be printed to the console in red and SQL
  2567. statements will be syntax highlighted.
  2568. .sp
  2569. Example usage:
  2570. .INDENT 0.0
  2571. .INDENT 3.5
  2572. .sp
  2573. .nf
  2574. .ft C
  2575. django\-admin runserver \-\-no\-color
  2576. .ft P
  2577. .fi
  2578. .UNINDENT
  2579. .UNINDENT
  2580. .INDENT 0.0
  2581. .TP
  2582. .B \-\-force\-color
  2583. .UNINDENT
  2584. .sp
  2585. Forces colorization of the command output if it would otherwise be disabled
  2586. as discussed in \fI\%Syntax coloring\fP\&. For example, you may want to pipe
  2587. colored output to another command.
  2588. .INDENT 0.0
  2589. .TP
  2590. .B \-\-skip\-checks
  2591. .UNINDENT
  2592. .sp
  2593. Skips running system checks prior to running the command. This option is only
  2594. available if the
  2595. \fBrequires_system_checks\fP command
  2596. attribute is not an empty list or tuple.
  2597. .sp
  2598. Example usage:
  2599. .INDENT 0.0
  2600. .INDENT 3.5
  2601. .sp
  2602. .nf
  2603. .ft C
  2604. django\-admin migrate \-\-skip\-checks
  2605. .ft P
  2606. .fi
  2607. .UNINDENT
  2608. .UNINDENT
  2609. .SH EXTRA NICETIES
  2610. .SS Syntax coloring
  2611. .INDENT 0.0
  2612. .TP
  2613. .B DJANGO_COLORS
  2614. .UNINDENT
  2615. .sp
  2616. The \fBdjango\-admin\fP / \fBmanage.py\fP commands will use pretty
  2617. color\-coded output if your terminal supports ANSI\-colored output. It
  2618. won\(aqt use the color codes if you\(aqre piping the command\(aqs output to
  2619. another program unless the \fI\%\-\-force\-color\fP option is used.
  2620. .SS Windows support
  2621. .sp
  2622. On Windows 10, the \fI\%Windows Terminal\fP application, \fI\%VS Code\fP, and PowerShell
  2623. (where virtual terminal processing is enabled) allow colored output, and are
  2624. supported by default.
  2625. .sp
  2626. Under Windows, the legacy \fBcmd.exe\fP native console doesn\(aqt support ANSI
  2627. escape sequences so by default there is no color output. In this case either of
  2628. two third\-party libraries are needed:
  2629. .INDENT 0.0
  2630. .IP \(bu 2
  2631. Install \fI\%colorama\fP, a Python package that translates ANSI color codes into
  2632. Windows API calls. Django commands will detect its presence and will make use
  2633. of its services to color output just like on Unix\-based platforms.
  2634. \fBcolorama\fP can be installed via pip:
  2635. .INDENT 2.0
  2636. .INDENT 3.5
  2637. .sp
  2638. .nf
  2639. .ft C
  2640. \&...\e> py \-m pip install colorama
  2641. .ft P
  2642. .fi
  2643. .UNINDENT
  2644. .UNINDENT
  2645. .IP \(bu 2
  2646. Install \fI\%ANSICON\fP, a third\-party tool that allows \fBcmd.exe\fP to process
  2647. ANSI color codes. Django commands will detect its presence and will make use
  2648. of its services to color output just like on Unix\-based platforms.
  2649. .UNINDENT
  2650. .sp
  2651. Other modern terminal environments on Windows, that support terminal colors,
  2652. but which are not automatically detected as supported by Django, may "fake" the
  2653. installation of \fBANSICON\fP by setting the appropriate environmental variable,
  2654. \fBANSICON="on"\fP\&.
  2655. .SS Custom colors
  2656. .sp
  2657. The colors used for syntax highlighting can be customized. Django
  2658. ships with three color palettes:
  2659. .INDENT 0.0
  2660. .IP \(bu 2
  2661. \fBdark\fP, suited to terminals that show white text on a black
  2662. background. This is the default palette.
  2663. .IP \(bu 2
  2664. \fBlight\fP, suited to terminals that show black text on a white
  2665. background.
  2666. .IP \(bu 2
  2667. \fBnocolor\fP, which disables syntax highlighting.
  2668. .UNINDENT
  2669. .sp
  2670. You select a palette by setting a \fI\%DJANGO_COLORS\fP environment
  2671. variable to specify the palette you want to use. For example, to
  2672. specify the \fBlight\fP palette under a Unix or OS/X BASH shell, you
  2673. would run the following at a command prompt:
  2674. .INDENT 0.0
  2675. .INDENT 3.5
  2676. .sp
  2677. .nf
  2678. .ft C
  2679. export DJANGO_COLORS="light"
  2680. .ft P
  2681. .fi
  2682. .UNINDENT
  2683. .UNINDENT
  2684. .sp
  2685. You can also customize the colors that are used. Django specifies a
  2686. number of roles in which color is used:
  2687. .INDENT 0.0
  2688. .IP \(bu 2
  2689. \fBerror\fP \- A major error.
  2690. .IP \(bu 2
  2691. \fBnotice\fP \- A minor error.
  2692. .IP \(bu 2
  2693. \fBsuccess\fP \- A success.
  2694. .IP \(bu 2
  2695. \fBwarning\fP \- A warning.
  2696. .IP \(bu 2
  2697. \fBsql_field\fP \- The name of a model field in SQL.
  2698. .IP \(bu 2
  2699. \fBsql_coltype\fP \- The type of a model field in SQL.
  2700. .IP \(bu 2
  2701. \fBsql_keyword\fP \- An SQL keyword.
  2702. .IP \(bu 2
  2703. \fBsql_table\fP \- The name of a model in SQL.
  2704. .IP \(bu 2
  2705. \fBhttp_info\fP \- A 1XX HTTP Informational server response.
  2706. .IP \(bu 2
  2707. \fBhttp_success\fP \- A 2XX HTTP Success server response.
  2708. .IP \(bu 2
  2709. \fBhttp_not_modified\fP \- A 304 HTTP Not Modified server response.
  2710. .IP \(bu 2
  2711. \fBhttp_redirect\fP \- A 3XX HTTP Redirect server response other than 304.
  2712. .IP \(bu 2
  2713. \fBhttp_not_found\fP \- A 404 HTTP Not Found server response.
  2714. .IP \(bu 2
  2715. \fBhttp_bad_request\fP \- A 4XX HTTP Bad Request server response other than 404.
  2716. .IP \(bu 2
  2717. \fBhttp_server_error\fP \- A 5XX HTTP Server Error response.
  2718. .IP \(bu 2
  2719. \fBmigrate_heading\fP \- A heading in a migrations management command.
  2720. .IP \(bu 2
  2721. \fBmigrate_label\fP \- A migration name.
  2722. .UNINDENT
  2723. .sp
  2724. Each of these roles can be assigned a specific foreground and
  2725. background color, from the following list:
  2726. .INDENT 0.0
  2727. .IP \(bu 2
  2728. \fBblack\fP
  2729. .IP \(bu 2
  2730. \fBred\fP
  2731. .IP \(bu 2
  2732. \fBgreen\fP
  2733. .IP \(bu 2
  2734. \fByellow\fP
  2735. .IP \(bu 2
  2736. \fBblue\fP
  2737. .IP \(bu 2
  2738. \fBmagenta\fP
  2739. .IP \(bu 2
  2740. \fBcyan\fP
  2741. .IP \(bu 2
  2742. \fBwhite\fP
  2743. .UNINDENT
  2744. .sp
  2745. Each of these colors can then be modified by using the following
  2746. display options:
  2747. .INDENT 0.0
  2748. .IP \(bu 2
  2749. \fBbold\fP
  2750. .IP \(bu 2
  2751. \fBunderscore\fP
  2752. .IP \(bu 2
  2753. \fBblink\fP
  2754. .IP \(bu 2
  2755. \fBreverse\fP
  2756. .IP \(bu 2
  2757. \fBconceal\fP
  2758. .UNINDENT
  2759. .sp
  2760. A color specification follows one of the following patterns:
  2761. .INDENT 0.0
  2762. .IP \(bu 2
  2763. \fBrole=fg\fP
  2764. .IP \(bu 2
  2765. \fBrole=fg/bg\fP
  2766. .IP \(bu 2
  2767. \fBrole=fg,option,option\fP
  2768. .IP \(bu 2
  2769. \fBrole=fg/bg,option,option\fP
  2770. .UNINDENT
  2771. .sp
  2772. where \fBrole\fP is the name of a valid color role, \fBfg\fP is the
  2773. foreground color, \fBbg\fP is the background color and each \fBoption\fP
  2774. is one of the color modifying options. Multiple color specifications
  2775. are then separated by a semicolon. For example:
  2776. .INDENT 0.0
  2777. .INDENT 3.5
  2778. .sp
  2779. .nf
  2780. .ft C
  2781. export DJANGO_COLORS="error=yellow/blue,blink;notice=magenta"
  2782. .ft P
  2783. .fi
  2784. .UNINDENT
  2785. .UNINDENT
  2786. .sp
  2787. would specify that errors be displayed using blinking yellow on blue,
  2788. and notices displayed using magenta. All other color roles would be
  2789. left uncolored.
  2790. .sp
  2791. Colors can also be specified by extending a base palette. If you put
  2792. a palette name in a color specification, all the colors implied by that
  2793. palette will be loaded. So:
  2794. .INDENT 0.0
  2795. .INDENT 3.5
  2796. .sp
  2797. .nf
  2798. .ft C
  2799. export DJANGO_COLORS="light;error=yellow/blue,blink;notice=magenta"
  2800. .ft P
  2801. .fi
  2802. .UNINDENT
  2803. .UNINDENT
  2804. .sp
  2805. would specify the use of all the colors in the light color palette,
  2806. \fIexcept\fP for the colors for errors and notices which would be
  2807. overridden as specified.
  2808. .SS Bash completion
  2809. .sp
  2810. If you use the Bash shell, consider installing the Django bash completion
  2811. script, which lives in \fBextras/django_bash_completion\fP in the Django source
  2812. distribution. It enables tab\-completion of \fBdjango\-admin\fP and
  2813. \fBmanage.py\fP commands, so you can, for instance...
  2814. .INDENT 0.0
  2815. .IP \(bu 2
  2816. Type \fBdjango\-admin\fP\&.
  2817. .IP \(bu 2
  2818. Press [TAB] to see all available options.
  2819. .IP \(bu 2
  2820. Type \fBsql\fP, then [TAB], to see all available options whose names start
  2821. with \fBsql\fP\&.
  2822. .UNINDENT
  2823. .sp
  2824. See /howto/custom\-management\-commands for how to add customized actions.
  2825. .SS Black formatting
  2826. .sp
  2827. .sp
  2828. The Python files created by \fI\%startproject\fP, \fI\%startapp\fP,
  2829. \fI\%optimizemigration\fP, \fI\%makemigrations\fP, and
  2830. \fI\%squashmigrations\fP are formatted using the \fBblack\fP command if it is
  2831. present on your \fBPATH\fP\&.
  2832. .sp
  2833. If you have \fBblack\fP globally installed, but do not wish it used for the
  2834. current project, you can set the \fBPATH\fP explicitly:
  2835. .INDENT 0.0
  2836. .INDENT 3.5
  2837. .sp
  2838. .nf
  2839. .ft C
  2840. PATH=path/to/venv/bin django\-admin makemigrations
  2841. .ft P
  2842. .fi
  2843. .UNINDENT
  2844. .UNINDENT
  2845. .sp
  2846. For commands using \fBstdout\fP you can pipe the output to \fBblack\fP if needed:
  2847. .INDENT 0.0
  2848. .INDENT 3.5
  2849. .sp
  2850. .nf
  2851. .ft C
  2852. django\-admin inspectdb | black \-
  2853. .ft P
  2854. .fi
  2855. .UNINDENT
  2856. .UNINDENT
  2857. .INDENT 0.0
  2858. .TP
  2859. .B django.core.management.call_command(name, *args, **options)
  2860. .UNINDENT
  2861. .sp
  2862. To call a management command from code use \fBcall_command\fP\&.
  2863. .INDENT 0.0
  2864. .TP
  2865. .B \fBname\fP
  2866. the name of the command to call or a command object. Passing the name is
  2867. preferred unless the object is required for testing.
  2868. .TP
  2869. .B \fB*args\fP
  2870. a list of arguments accepted by the command. Arguments are passed to the
  2871. argument parser, so you can use the same style as you would on the command
  2872. line. For example, \fBcall_command(\(aqflush\(aq, \(aq\-\-verbosity=0\(aq)\fP\&.
  2873. .TP
  2874. .B \fB**options\fP
  2875. named options accepted on the command\-line. Options are passed to the command
  2876. without triggering the argument parser, which means you\(aqll need to pass the
  2877. correct type. For example, \fBcall_command(\(aqflush\(aq, verbosity=0)\fP (zero must
  2878. be an integer rather than a string).
  2879. .UNINDENT
  2880. .sp
  2881. Examples:
  2882. .INDENT 0.0
  2883. .INDENT 3.5
  2884. .sp
  2885. .nf
  2886. .ft C
  2887. from django.core import management
  2888. from django.core.management.commands import loaddata
  2889. management.call_command(\(aqflush\(aq, verbosity=0, interactive=False)
  2890. management.call_command(\(aqloaddata\(aq, \(aqtest_data\(aq, verbosity=0)
  2891. management.call_command(loaddata.Command(), \(aqtest_data\(aq, verbosity=0)
  2892. .ft P
  2893. .fi
  2894. .UNINDENT
  2895. .UNINDENT
  2896. .sp
  2897. Note that command options that take no arguments are passed as keywords
  2898. with \fBTrue\fP or \fBFalse\fP, as you can see with the \fBinteractive\fP option above.
  2899. .sp
  2900. Named arguments can be passed by using either one of the following syntaxes:
  2901. .INDENT 0.0
  2902. .INDENT 3.5
  2903. .sp
  2904. .nf
  2905. .ft C
  2906. # Similar to the command line
  2907. management.call_command(\(aqdumpdata\(aq, \(aq\-\-natural\-foreign\(aq)
  2908. # Named argument similar to the command line minus the initial dashes and
  2909. # with internal dashes replaced by underscores
  2910. management.call_command(\(aqdumpdata\(aq, natural_foreign=True)
  2911. # \(gause_natural_foreign_keys\(ga is the option destination variable
  2912. management.call_command(\(aqdumpdata\(aq, use_natural_foreign_keys=True)
  2913. .ft P
  2914. .fi
  2915. .UNINDENT
  2916. .UNINDENT
  2917. .sp
  2918. Some command options have different names when using \fBcall_command()\fP instead
  2919. of \fBdjango\-admin\fP or \fBmanage.py\fP\&. For example, \fBdjango\-admin
  2920. createsuperuser \-\-no\-input\fP translates to \fBcall_command(\(aqcreatesuperuser\(aq,
  2921. interactive=False)\fP\&. To find what keyword argument name to use for
  2922. \fBcall_command()\fP, check the command\(aqs source code for the \fBdest\fP argument
  2923. passed to \fBparser.add_argument()\fP\&.
  2924. .sp
  2925. Command options which take multiple options are passed a list:
  2926. .INDENT 0.0
  2927. .INDENT 3.5
  2928. .sp
  2929. .nf
  2930. .ft C
  2931. management.call_command(\(aqdumpdata\(aq, exclude=[\(aqcontenttypes\(aq, \(aqauth\(aq])
  2932. .ft P
  2933. .fi
  2934. .UNINDENT
  2935. .UNINDENT
  2936. .sp
  2937. The return value of the \fBcall_command()\fP function is the same as the return
  2938. value of the \fBhandle()\fP method of the command.
  2939. .SH OUTPUT REDIRECTION
  2940. .sp
  2941. Note that you can redirect standard output and error streams as all commands
  2942. support the \fBstdout\fP and \fBstderr\fP options. For example, you could write:
  2943. .INDENT 0.0
  2944. .INDENT 3.5
  2945. .sp
  2946. .nf
  2947. .ft C
  2948. with open(\(aq/path/to/command_output\(aq, \(aqw\(aq) as f:
  2949. management.call_command(\(aqdumpdata\(aq, stdout=f)
  2950. .ft P
  2951. .fi
  2952. .UNINDENT
  2953. .UNINDENT
  2954. .SH AUTHOR
  2955. Django Software Foundation
  2956. .SH COPYRIGHT
  2957. Django Software Foundation and contributors
  2958. .\" Generated by docutils manpage writer.
  2959. .