Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Behr, Svenja
Django_Blog
Commits
fcc3c100
Commit
fcc3c100
authored
Jun 28, 2020
by
Tang, Alexander
Browse files
Readme angepasst.
parent
bab58aab
Changes
1
Hide whitespace changes
Inline
Side-by-side
README.md
View file @
fcc3c100
...
...
@@ -94,7 +94,7 @@ Open the link http://127.0.0.1:8000/ and check, if the page opens up and shows s
**Note!**
If you see a message, telling you to perform manage.py commands, something went wrong, as the
start page content could not be found. Try to redo the steps above, please.
#
AB HIER NOCH SAUBER MACHEN
#
Intern oft verwendete Befehle
### Django Befehle
#### Neues Module (App)
`manage.py startapp *appname*`
...
...
@@ -109,118 +109,3 @@ start page content could not be found. Try to redo the steps above, please.
`manage.py migrate`
Achtung: Wenigstens einmal auf alles, sonst gehts nicht.
#### Admin-Nutzer
`manage.py createsuperuser`
|(changepassword)
#### Django-Klassen -> Datenbankmodel
https://docs.djangoproject.com/en/3.0/ref/models/fields/
in unserem Projekt vielleicht so etwas wie
```
class Blog(models.Model)
title = models.CharField(max_length=80) #maximal 80 Zeichen
image = models.ImageField(upload_to='...') #Wenn Bilder -> pillow ext laden
```
#### Dann Model in admin.py registrieren
```
# Register your models here.
from .models import Blog
admin.site.register(Blog)
```
#### settings.py -> Medienordner setzen
```
MEDIA_URL = '/media/' # kann natuerlich auch anders benannt werden
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')` # speichert Medien im Ordner 'media ab'
```
#### Statische Bilder anzeigen lassen urls.py
```
<...>
from django.conf.urls.static import static
from django.conf import settings
<...>
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
```
#### Prozess um weitere Seiten einzubinden
**1. Setting up URL**
<br>
urls.py: add path and import views
<br>
**2. Setting up View (eigentlich der Controller)**
<br>
create new function in views.py, e.g. def home(request):
<br>
**3. Return a template (eigentlich die View)**
<br>
create directories in project folder templates/...
<br>
create html file
<br>
#### Datenbank-Daten (Objekte) in Seite einbinden
**1. views.py**
```
from .models import Blog
<...>
def home(request):
blogObjects = Blog.objects().all # grabs all objects from the DB table 'Blog'
return render(request, '<Website e.g. <App folder>/home.html', {'blogobjects':blogobjects})
--> damit bekommt man ein QuerySet zurückgegeben
```
**2. home.html**
```
{% for blogobject in blogobjects %}
{{ blogobject}}
{% endfor %}
```
#### CKEditor Befehle
**1. Installation**
```
pip install django-ckeditor
```
**2. Vorbereitende Maßnahmen (schon durchgeführt und nicht nochmal nötig)**
Für CKEditor ohne Uploader
-Add ckeditor to your INSTALLED_APPS setting.
-Run the collectstatic management command:
```
manage.py collectstatic
```
This will copy static CKEditor required media resources into the directory given by the STATIC_ROOT setting.
See Django’s documentation on managing static files for more info.
Zusätzlich für CKEditor mit Uploader
-Add ckeditor_uploader to your INSTALLED_APPS setting.
-Add a CKEDITOR_UPLOAD_PATH setting to the project’s settings.py file. This setting specifies a relative path to
your CKEditor media upload directory. CKEditor uses Django’s storage API. By default, Django uses the file system
storage backend (it will use your MEDIA_ROOT and MEDIA_URL) and if you don’t use a different backend you have to
have write permissions for the CKEDITOR_UPLOAD_PATH path within MEDIA_ROOT, i.e.:
```
CKEDITOR_UPLOAD_PATH = "uploads/"
```
When using default file system storage, images will be uploaded to “uploads” folder in your
MEDIA_ROOT and urls will be created against MEDIA_URL (/media/uploads/image.jpg).
**3. Benutzung**
Field
The quickest way to add rich text editing capabilities to your models is to use the included RichTextField model
field type. A CKEditor widget is rendered as the form field but in all other regards the field behaves as the
standard Django TextField. For example:
```
from django.db import models
from ckeditor.fields import RichTextField
class Post(models.Model):
content = RichTextField()
```
For file upload support use RichTextUploadingField from ckeditor_uploader.fields.
**4. Doc**
Mehr unter: https://django-ckeditor.readthedocs.io/en/latest/#usage
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment