Also das war ein wirklich blöder Kommentar, den ich oben gemacht habe. :-)
Hier ist eine richtige Antwort! Yeoman ist einfach ein Gerüstwerkzeug für uns, um schnell css, js und html Dateien zu erzeugen. Ich benutze es komplett entkoppelt, sauber getrennt vom Django.
Hier ist die Baumstruktur der Frontend-Site.
/Users/calvin/work/yeoman-test/
|~app/
| |~scripts/
| | |~controllers/
| | | `-main.js
| | |~vendor/
| | | |-angular.js
| | | |-angular.min.js
| | | |-es5-shim.min.js
| | | `-json3.min.js
| | `-app.js
| |~styles/
| | |-bootstrap.css
| | `-main.css
| |+views/
| |-.buildignore
| |-.htaccess
| |-404.html
| |-favicon.ico
| |-index.html
| `-robots.txt
|~test/
| |+spec/
| `+vendor/
|-.gitattributes
|-.npmignore
|-Gruntfile.js
|-package.json
`-testacular.conf.js
Und hier ist die Baumstruktur für die Anwendung django als reine json Web-Service fungiert. Mit Django-Tastypie.
/Users/calvin/work/yeomandjango/
|~deploy/
| |-crontab
| |-gunicorn.conf.py
| |-live_settings.py*
| |-nginx.conf
| `-supervisor.conf
|~requirements/
| `-project.txt
|+static/
|-.gitignore
|-.hgignore
|-__init__.py
|-__init__.pyc
|-dev.db
|-fabfile.py
|-local_settings.py
|-local_settings.pyc
|-manage.py*
|-settings.py
|-settings.pyc
|-urls.py
`-urls.pyc
Durch die django Webservice von Domain und Urls wie http://service.mysite.com/api/v1/ läuft und unser Frontend Yeoman mit erzeugt „statisch“ Website http://mysite.com diese API-URLs aufrufen je nach Bedarf.
Der Yeoman generierte AngularJS App einfach POSTS/GETS/PUT/DELETE die API Ressourcen/URLs von unseren Django-Tastypie APIs gegeben.
Dies ist eine lose gekoppelte Konfiguration, die Sie berücksichtigen können.
Beachten Sie jedoch, dass diese Einrichtung "domänenübergreifende API-Anfragen" ausführt. Das bedeutet, dass wir auf unserer "serverseitigen" Django-Anwendung mit CORS umgehen müssen.
Hier ist ein Beispiel für ein Middleware-Snippet, das auf der django-Serverseite implementiert werden muss, damit dies funktioniert.
import re
from django.utils.text import compress_string
from django.utils.cache import patch_vary_headers
from django import http
try:
import settings
XS_SHARING_ALLOWED_ORIGINS = settings.XS_SHARING_ALLOWED_ORIGINS
XS_SHARING_ALLOWED_METHODS = settings.XS_SHARING_ALLOWED_METHODS
except:
XS_SHARING_ALLOWED_ORIGINS = '*'
XS_SHARING_ALLOWED_METHODS = ['POST','GET','OPTIONS', 'PUT', 'DELETE']
class XsSharing(object):
"""
This middleware allows cross-domain XHR using the html5 postMessage API.
Access-Control-Allow-Origin: http://foo.example
Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE
"""
def process_request(self, request):
if 'HTTP_ACCESS_CONTROL_REQUEST_METHOD' in request.META:
response = http.HttpResponse()
response['Access-Control-Allow-Origin'] = XS_SHARING_ALLOWED_ORIGINS
response['Access-Control-Allow-Methods'] = ",".join(XS_SHARING_ALLOWED_METHODS)
return response
return None
def process_response(self, request, response):
# Avoid unnecessary work
if response.has_header('Access-Control-Allow-Origin'):
return response
response['Access-Control-Allow-Origin'] = XS_SHARING_ALLOWED_ORIGINS
response['Access-Control-Allow-Methods'] = ",".join(XS_SHARING_ALLOWED_METHODS)
return response
Ich persönlich würde empfehlen, dass Sie mit django Brunch anstelle - https://github.com/sebastibe/brunch-django-examples Brunch ist auch eine reifere Bibliothek im Vergleich zu Yeoman. Aber das beantwortet deine ursprüngliche Frage nicht. Daher nur ein Kommentar hier. :-) –