This is a basic Django (1.11) project and singular application, which includes login and registration features, along with validations. This is a useful django 1.11 template to build larger projects, with the basic login and validation features ready to go.
Note: This project must be updated after being cloned. Instructions for updating core Django files is listed below. Any failures updating Django variables to your own project and application variables, will cause the application to break.
Just to let you know there are about 30+ steps listed below on how to customize this template and create a new project from it. You can definitely pursue customizing this on your own, and may update variables by finding errors using the debugger and following them to completion. If however, you get lost, you can use the steps below to see step by step exactly, how to take this repo and turn it into a new project. It's one of those things that on the surface is more intimidating than it actually is. Essentially, in a nut shell, we've got to update all old project and application variable names to our new project.
Disclaimer: It might even be faster to create a new Django project from scratch, and copy and paste in the basic routes or views.
- Clone this repository into a folder where you'd like it to live.
- Rename the
django_template
folder to your{{project_name}}
of choice. Note: {{variables}} will be used from now on to denote variables you must update. The double curly brackets are not to be included - Open your now renamed project folder, and rename the containing
django_template
folder (whose path is now,{{project_name}}\django_template
), to the same{{project_name}}
used previously. Your path to this folder should now be,{{project_name}}\{{project_name}}
. - Open
manage.py
in the root of your project folder. The path should be:{{project_name}}\manage.py
. - On line 6 in
manage.py
, rename the second parameter insetdefault()
from:django_template.settings
to{{project_name}}.settings
. Save changes and close this file. - In the root of your
{{project_name}}
folder, navigate into the\apps
folder ({{project_name}}\apps
). Rename the containing folder fromtemplate
to the name of your app (usually a shorthand of your{{project_name}}
). In this case, we'll call it{{app_name}}
. So,{{project_name}}\apps\template
should now be named{{project_name}}\apps\{{app_name}}
. - Navigate into the newly renamed
{{app_name}}
folder. - Open
apps.py
({{project_name}}\apps\{{app_name}}\apps.py
). On line 7, renametemplate
to your{{app_name}}
. Save and close the file. - Open
views.py
in the same folder ({{project_name}}\apps\{{app_name}}\views.py
). - In the first method,
index()
, at the very bottom of the method, change the linereturn render(request, "template/index.html")
toreturn render(request, "{{app_name}}/index.html")
. - In second to last method,
get_dashboard_data()
, at the very bottom of thetry
statement, update the linereturn render(request, "template/dashboard.html", dashboard_data)
toreturn render(request, "{{app_name}}/dashboard.html", dashboard_data)
. Save the file and close it. Note: Currently, the only dashboard data retreived is that of the current user. This could be vastly added onto, and if not needed can be removed (be sure to remove thefrom . import dashboard
if not needed). - Open
\template
folder inside of the{{app_name}}
folder ({{project_name}}\apps\{{app_name}}\templates
). - Rename the containing folder,
template
to{{app_name}}
. This name must be your app name. - Navigate now into the newly renamed
{{app_name}}
folder ({{project_name}}\apps\{{app_name}}\templates\{{app_name}}
). - Once inside, open both
index.html
anddashboard.html
. Edit the<link rel="stylesheet">
lines from<link rel="stylesheet" href="{% static 'template/css/style.css' %}">
to<link rel="stylesheet" href="{% static '{{app_name}}/css/style.css' %}">
, replacing any references totemplate
and instead to your{{app_name}}
. - Also change the the
<title>
tags in each header, updating the name of the page to whatever your needs may be. Save and close both files. - Navigate up a directory back to the
{{project_name}}\apps\{{app_name}}\
. - Navigate into
/static
,{{project_name}}\apps\{{app_name}}\static
. - Change
template
to{{app_name}}
. This should be the same name you used when you renamed your last folder. The previous folder{{project_name}}\apps\{{app_name}}\static\template
should now be:{{project_name}}\apps\{{app_name}}\static\{{app_name}}
. - The folder structures have all been updated now. We've got to now update all of the Django settings, and make a few changes to a handful more files. Take a breath and let's finish this up.
- Navigate back to the
{{project_name}}
folder (root of your project). Once in this folder, navigate into the{{app_name}}
directory (notapps
). You should now be in{{project_name}}\{{app_name}}
. - Open
urls.py
({{project_name}}\{{app_name}}\urls.py
), change the line:url(r'^', include("apps.template.urls"))
, tourl(r'^', include("apps.{{app_name}}.urls")),
updating your application name in theinclude()
parameters. Close and save this file. - Open
wsgi.py
in the same folder ({{project_name}}\{{app_name}}\wsgi.py
). Change the lineos.environ.setdefault("DJANGO_SETTINGS_MODULE", "django_template.settings")
toos.environ.setdefault("DJANGO_SETTINGS_MODULE", "{{project_name}}.settings")
. We are changing thedjango_template.settings
to our{{project_name}}.settings
-- this is not your{{app_name}}
, but{{project_name}}
- Open
settings.py
file in the same folder ({{project_name}}\{{app_name}}\settings.py
). Once in this file, make the following changes:SECRET_KEY
: Change the hash by changing 1 or 2 characters to different characters. Do not change the character count, just change a few characters so that the hash is now unique in comparison to the original file.INSTALLED_APPS
: Change'apps.template'
to'apps.{{app_name}}'
. This updates our settings.py file to point to our renamed app folder inside ofapps
.ROOT_URLCONF
: Updatedjango_template.urls
to{{project_name}}.urls
. This is not{{app_name}}
.WSGI_APPLICATION
: Updatedjango_template.wsgi.application
to{{project_name}}.wsgi.application
, updating the name to{{project_name}}
, not{{app_name}}
TIME_ZONE
: Note, this is currently set toAmerica/Los_Angeles
. You can set this back toUTC
if needed or adjust for your own timezone needs.- Save all changes and close this file.
- Delete all
*.pyc
files in{{project_name}}\{{project_name}}
(should be ~4 files). - Delete all
*.pyc
files in{{project_name}}\apps
(should be ~1 files). - Delete all
*.pyc
files in{{project_name}}\apps\{{app_name}}
(should be ~6 files). - Delete all files EXCEPT
__init__.py
in{{project_name}}\apps\{{app_name}}\migrations
- Save all changes to any files that may have not been saved. We are done editing files now and we've essentially created a unique project, and a new database with the new project and app name dictating table nomenclature.
- Open terminal. Navigate to the
{{project_name}}
folder in terminal. - Create a new
virtualenv
for this project.pip install
all packages in{{project_name}}\requirements.txt
. If you do not create a new virtualenv and if you do not install the pip packages, then the server will not start. - Once inside the root of our project, and once all packages are installed,
makemigrations
viapython manage.py makemigrations
in terminal. This will generate.pyc
files again and prepare our models for generation. - Then
migrate
viapython manage.py migrate
to actually generate the models. - Start the server:
python manage.py runserver
. Once the server attempts to run, any misnamed or missed variables from our updating process will break the application. If the server runs, then all app variables should now be updated properly.