Difference between revisions of "Django"

From rbachwiki
Jump to navigation Jump to search
(Replaced content with "==Create a new project== == Create a Django App == === Category===")
Tag: Replaced
 
Line 1: Line 1:
==[[Create a new project]]==
==[[Create a new project]]==


== Create a Django App ==
== [[Create a Django App]] ==
python manage.py startapp myapp
* this will create an new app in the projectname folder
 
* cd into my app folder and create a folder called templates
* create an html file in the templates folder
* Link the new template folder to the project
* edit the settings.py file
import os
 
* Scroll down to "TEMPLATES", edit section DIRS
'DIRS': [os.path.join(BASE_DIR, "myapp/templates")]
* Edit the views.py in your myapp folder
def myview(request):
    return render(request, "index.html")
* create a route file called urls.py
from django.urls import path
from . import views
urlpatterns = [
    path('myview/', views.myview)
]
*There is also a urls.py in the folder with settings
<pre>
from django.contrib import admin
from django.urls import path, include
 
urlpatterns = [
    path('myapp/',include('myapp.urls')),
    path('admin/', admin.site.urls),
]
 
</pre>


===[[Programming| Category]]===
===[[Programming| Category]]===

Latest revision as of 19:51, 26 April 2023