Django
We now have a basic map integration, but no backend. Seeing we already are using some python scripts and web functionality, why not use a python web framework. Our two main choices here are Flask and Django. Seeing Django does more setup automagically then Flask we will be using this.
If you have never used Django I highly recommend you follow there beginner tutorial. After an afternoon you'll understand be done with it and have a working understanding for Django development.
Our site is still very basic. All we really need is a view for the map and a URL redirector to it. Later we'll expand this a lot but it's always good to get a basic working system then bite off to much to begin with.
We are going to run few commands and not add much code for this.
Start off with creating the project:
django-admin startproject modeller
Run it to test it worked:
python manage.py runserver
Create our map app:
python manage.py startapp terrainmap
Now we need to add a view for our map webpage:
1 2 | def index(request): return render(request, 'terrainmap/index.html') |
The view links to our map template. So create the directory templates/terrainmap/ under our terrainmap app and copy the web page we previously made.
Link to all the static files with {% static %}
Next is the to add the URL of the view:
1 2 3 | urlpatterns = [ path('', views.index, name='index'), ] |
Comments
Post a Comment