-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_page.py
71 lines (57 loc) · 2.01 KB
/
make_page.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"""
Used to make new pages in the Django project
Usage: python make_page.py
Enter a list of names (separated by commas): name1, name2, name3...
This will create the following files:
- name.html
This will edit the following files:
- views.py
- urls.py
- main.html
The views.py file will have the following functions:
- def name(request)
The urls.py file will have the following path:
- path('name/', views.name, name='name'),
The main.html file will have the following block:
-
The name.html file will have the following block:
- {% extends 'main/main.html' %}
- {% load static %}
- {% block content %}
- {% endblock content %}
The name.html file will be created in the following directory:
- {project}/main/templates/main/
05/07/2024
"""
views = open("velocity/main/views.py", "a")
urls = open("velocity/main/urls.py", "a")
main_html = open("velocity/main/templates/main/main.html", "a")
# Create Page View
def create_page_view(name):
views.write(f"\n\ndef {name}(request): \n return render(request, 'main/{name}.html')")
# Create URL Path
def create_url_path(name):
urls.write(f"\n path('{name}/', views.{name}, name='{name}'),")
# Create HTML Template
def create_html_template(name):
new_html = open(f"velocity/main/templates/main/{name}.html", "a")
html_line1 = "{% extends 'main/landing_main.html' %}"
html_line2 = "{% load static %}"
html_line3 = "{% block content %}"
html_line4 = "{% endblock content %}"
new_html.write(f"{html_line1}"
f"\n{html_line2}"
f"\n{html_line3}"
f"\n{html_line4}")
# Close Files
def close_files():
views.close()
urls.close()
main_html.close()
if __name__ == "__main__":
names = input("Enter a list of names (separated by commas): ").split(",")
for name in names:
create_page_view(name.strip())
create_url_path(name.strip())
create_html_template(name.strip())
close_files()