# How to run scripts outside views.py?

**URL:** <https://forum.djangoproject.com/t/how-to-run-scripts-outside-views-py/13322>\
**Category:** Getting Started\
**Created:** [April 22, 2022, 3:57pm UTC](https://forum.djangoproject.com/t/how-to-run-scripts-outside-views-py/13322 "2022-04-22T15:57:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![RuszakMiklos](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/ruszakmiklos/32/6218_2.png) [@RuszakMiklos](https://forum.djangoproject.com/u/RuszakMiklos)\
**Post date:** [April 22, 2022, 3:57pm UTC](https://forum.djangoproject.com/t/how-to-run-scripts-outside-views-py/13322/1 "2022-04-22T15:57:21Z")

</div>

I have a very trivial question so please forgive me.  
Until this time I always worked in the views.py files. Now I made a script called anything.py and I like to run it.

In this file there is nothing special just a send\_mail function. If I run the server it does nothing. If I try to use the script in the views.py it works fine.

What should I do?

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [April 22, 2022, 4:17pm UTC](https://forum.djangoproject.com/t/how-to-run-scripts-outside-views-py/13322/2 "2022-04-22T16:17:18Z")

</div>

When do you want it to run?

- Does it run on a schedule?

- Does it run based on an event in the system?

- Does it run based on an event outside the system?

- Does it run completely outside the context of the server?

---

<div class="post-metadata">

**Author:** ![RuszakMiklos](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/ruszakmiklos/32/6218_2.png) [@RuszakMiklos](https://forum.djangoproject.com/u/RuszakMiklos)\
**Post date:** [April 22, 2022, 5:06pm UTC](https://forum.djangoproject.com/t/how-to-run-scripts-outside-views-py/13322/3 "2022-04-22T17:06:22Z")

</div>

Hi Ken! Thank you for your answer.  
My goal is to send monthly scheduled emails for specific users with crontab or with schedule ([GitHub - dbader/schedule: Python job scheduling for humans.](https://github.com/dbader/schedule)) but I’m stuck in the first step. I never did something like this so just like to be more familiar how these tasks go.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [April 22, 2022, 5:16pm UTC](https://forum.djangoproject.com/t/how-to-run-scripts-outside-views-py/13322/4 "2022-04-22T17:16:16Z")

</div>

I generally recommend something like this be created as a [Django custom management command](https://docs.djangoproject.com/en/4.0/howto/custom-management-commands/). You would then run this using the “manage.py” script, the same way you would run any other management command.
