Coder Social home page Coder Social logo

djangular's Introduction

djangular

A reusable app that provides better app integration with AngularJS. Djangular allows you to create AngularJS content per app, instead of creating a single massive AngularJS application inside of Django. This allows you to selectively use apps per site, as well as create a consistent structure across all of your Django apps.

This is intended to be a Django version of the angular-seed project (https://github.com/angular/angular-seed). The current mindset is to limit the amount of changes introduced by Djangular.

Features

  • Allows namespacing AngularJS content per Django app. This allows the AngularJS apps and modules to be included (or not) based on Django's settings, and enforces a consistent structure to your Django/AngularJS apps.
  • Includes an AngularJS module that includes a subset of features similar to what Django provides in its templates.
  • Adds a patch to AngularJS's $resource module, to enable end of URL slashes that Django requires.
  • Improves security by enabling of CSRF protection and JSON Vulnerability between Django and AngularJS.
  • Scripts to allow running JS Unit and E2E tests, similar to the Django test command. This was removed for the time being and will be (re-)included in a future release.
  • Does not dictate how you use AngularJS inside your Django app.

Requirements

  • Currently requires Python 2.7.
  • Supports Django >= 1.5, <= 1.9
  • Supports AngularJS 1.2+ (including 1.3.x).
  • Local installs of Node.js and Karma for testing.

Installation

  • You may install directly from pypi:

      pip install djangular
    
  • Or download the source and install it in a terminal/console:

      python setup.py install
    
  • Or download the source and move the djangular directory inside your django project as an app (this is the least recommended approach).

  • Djangular needs to be placed as an app inside a Django project and added to the INSTALLED_APPS setting.

      INSTALLED_APPS = (
          ...
          'djangular',
          ...
      )
    
  • You will need to obtain a version of AngularJS and place it in the static folder of one of your Django apps. Djangular no longer includes a version of AngularJS, since it updates too frequently.

Including AngularJS content in your Django Apps

The most popular feature of Djangular, this will both include and namespace your AngularJS content inside your Django apps. Each Django app has its own "angular" folder, with a layout matching the angular-seed project. As a result, the URLs for these get grouped into the STATIC_URL structure of Django.

  • The staticfiles contrib library will need to be included in the INSTALLED_APPS setting.

      INSTALLED_APPS = (
          ...
          'django.contrib.staticfiles',
          'djangular',
          ...
      )
    
  • The STATICFILES_FINDERS needs to be updated to include djangular.finders.NamespacedAngularAppDirectoriesFinder.

      STATICFILES_FINDERS = (
          'django.contrib.staticfiles.finders.FileSystemFinder',
          'django.contrib.staticfiles.finders.AppDirectoriesFinder',
          'djangular.finders.NamespacedAngularAppDirectoriesFinder'
      )
    
  • Because of this new finder, the findstatic and collectstatic commands will place the angular files in each app in an associated an <app_name>/ folder. You will not need to namespace each of your static directories with the name of your Django application (unless you really want to).

    • Example: If you have a Django app named foo and you are using the default STATIC_URL in your settings, the main AngularJS module named foo would be found at foo/angular/app.js on the file system and at static/foo/app.js from the browser.
    • This namespacing is done automatically. This a foo app and a bar app can both have an app.js inside their angular directories, and they will not collide.
    • Note: Because of these URLs, referring to AngularJS content in a separate app should use a ../<separate_app>/ URL. This will help significantly during testing to make sure paths are correct.
    • Note: It is recommended to namespace the AngularJS code the same name as the Django app. The created JS files do this already.
  • To create an app that is already setup with the djangular (or angular-seed) structure, run python manage.py startangularapp <app_name> from the command line. This will create the files and directory structures needed for you to get started.

Including some Django template-like features in your AngularJS templates

One of the challenges in using AngularJS inside of Django is that you may not have access to some needed variables that are always included in Django templates. Djangular includes an AngularJS module to help with that.

  • To use the AngularJS module that Djangular provides you, you'll need to add the djangular app to your projects URLs.

      urlpatterns = patterns('',
          ...
          url(r'^djangular/', include('djangular.urls')),
          ...
      )
    
  • Alternatively, you may specify the DjangularModuleTemplateView specifically, and customize the url.

      from djangular.views import DjangularModuleTemplateView
      ...
    
      urlpatterns = patterns('',
          ...
          url(r'<custom_path>/djangular.js',
              DjangularModuleTemplateView.as_view()),
          ...
      )
    

This will add a djangular AngularJS module to your front end code. This module includes a DjangoProperties constant that includes whether the current user is authenticated, the username, groups and roles of the current user and the static and media urls from Django settings. It also includes a django filter, which does some basic substitution based on the properties constant.

Enforcing the end slashes of your AngularJS Resources

$resource is a convenient way to create REST-like services in AngularJS. However, there currently is a bug in $resource that will strip the ending slash, which means that $resource is unusable unless settings.APPEND_SLASHES is set to FALSE.

Djangular used to patch this automatically, but it now includes a separate file (djangular/static/js/resource_patch.js) to handle this issue. Simply include that javascript file in your page after you have loaded angular-resource.js and ending slashes will be preserved in $resource.

Enabling CSRF protection in AngularJS Templates

Djangular includes a JSON Vulnerability middleware that AngularJS knows how to process. To include this protection, add djangular.middleware.AngularJsonVulnerabilityMiddleware to the MIDDLEWARE_CLASSES setting. This only affects JSON requests (based on Content-Type), so this can be located fairly low in the middleware stack.

    MIDDLEWARE_CLASSES = (
        ...
        'djangular.middleware.AngularJsonVulnerabilityMiddleware'
    )

Once you have enabled CSRF protection in Django by adding the middleware django.middleware.csrf.CsrfViewMiddleware to the MIDDLEWARE_CLASSES setting, you may use the same protection in AngularJS templates in addition to Django template. There are two different ways to enable this protection via djangular:

  • Make your main app dependent on the djangular module and use the included csrf-token directive (that wraps the Django csrf_token template tag) inside the appropriate form tags in your HTML.

      // Inside your JavaScript
      angular.module('myApp', ['djangular', ...]);
      ...
      <!-- In your AngularJS Template -->
      <div ng-app="my-app">
          ...
          <form ...>
              <csrf-token></csrf-token>
          </form>
      </div>
    
  • Make your main app dependent on the djangular.csrf, which will add the appropriate CSRF Token Header in all POSTs, PUTs and DELETEs. Note that this way is vulnerable to cross-site scripting if you make a post to a domain outside your control.

      angular.module('myApp', ['djangular.csrf', ...]);
    

If you allow a user to login (or logout) and don't redirect or reload the page, the tags and cookies provided by both methods above will be stale. The second option (using the djangular.csrf module) provides a UpdateCSRFToken function that can be invoked with the new CSRF Token value.

Using Djangular in your Django Project

This section describes some best practices in using Djangular. Please note that these are guidelines and recommendations, but not the only way to use this project.

AngularJS as purely static content

The first way to use djangular is to have all of your static content live inside an angular app. This is perhaps the "most correct" way from an AngularJS standpoint and perhaps the "least correct" way from a traditional Django perspective.

In doing this, you are only (or almost only) serving content from your static domain and your Django development becomes strictly back-end focused for REST and/or service calls. Few to none of your Django views will produce HTML. You can provide a redirect from a Django view to your static pages (if you like), although this can seem strange when your static content is served from a completely different domain. You may need to configure your web servers to allow remote Ajax calls from your static domain.

This approach allows you to use AngularJS with any number of back-ends, as (again) your Django app becomes an API for your AngularJS code to call. This approach can be very different from how your application is currently architected.

From our experience, if you decide to do this, we would recommend using local, relative URLs to navigate between the apps instead of specifying the full URL. However, there are times when you will need to specify the full URL.

There is an AngularJS module called djangular that is rendered via the Django templating engine to obtain common template variables like the STATIC_URL, MEDIA_URL, the User object, etc. This app includes a service called DjangoProperties, which will enable you to get access to those variables, and a django filter, which follows the standard AngularJS filtering rules. The URL for this JavaScript is /djangular/app.js (note that is not static).

The following is a sample route config that uses the aforementioned djangular angular app. Because AngularJS has not set up the $filter directive during the route configuration, the DjangoProperties constant is the only way to obtain the STATIC_URL. Using 'sample' as the name of the Django/AngularJS app:

angular.module('sample', [
    'djangular', 'sample.filters', 'sample.services', 'sample.directives',
    'sample.controllers'
    ]).config([
        '$routeProvider','DjangoProperties',
        function($routeProvider, DjangoProperties) {
            $routeProvider.when('/view1', {
                templateUrl: DjangoProperties.STATIC_URL +
                    'sample/view1/view1.html', controller: 'View1Ctrl'});
            $routeProvider.when('/view2', {
                templateUrl: DjangoProperties.STATIC_URL +
                    'sample/view2/view2.html', controller: 'View2Ctrl'});
            $routeProvider.otherwise({redirectTo: '/view1'});
        }
    ]);

Django Templates as AngularJS Templates

Another way to integrate is to use your Django templates as your AngularJS templates. To do this, we highly recommend using Django 1.5 and heavy use of the {% verbatim %} tag, since the Django and AngularJS templating syntaxes are identical.

The big advantage of this is that it allows you to use all of the existing template tags and ways of thinking that you are accustomed to using. If you are integrating AngularJS into an existing Django project, this will seem the most appealing.

The downsides to this method are the following:

  • The AngularJS developers recommend not doing this, because it is very easy to get confused about which part of the template is being rendered on the server side and which is being rendered on the client side. Almost every developer on our team has tripped on this once or twice.
  • The vast majority of HTML that your app is producing is the same on every load... and should be static. However, without some cache configuration, the server will have to render the content on every single request, resulting in poorer performance.

Using Django Templates to render the skeleton of the app

What our team currently does is use a Django Template to render the skeleton of every page, but the rest of the page (the partials, CSS and JS) are all included in the AngularJS app. This way, none of the CSS/JS dependencies are duplicated in multiple places.

When our app renders the content, we pass in two variables to the RequestContext (and thus, to the template). The app_name, which is the name of the app, and app_dependencies, which is a list of app names whom the AngularJS app is dependent on. We make heavy use of Django Rest Framework (http://django-rest-framework.org/) to produce our views/REST Services and Django Pipeline (https://github.com/cyberdelia/django-pipeline) to do our app packaging and JS/CSS Compression.

The template (more or less) looks like the following:

{% load compressed %}  <!-- We use django-pipeline to do our packaging -->

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>App Title</title>
	<link rel="shortcut icon" href="{{ STATIC_URL }}images/app.ico" />

    <!--CSS imports-->
    {% for dependency in app_dependencies %}
        {% compressed_css dependency %}
    {% endfor %}
    {% compressed_css app_name %}

    <!--AngularJS library imports-->
    <script src="{{ STATIC_URL }}angular/angular-min.js"></script>

    <!--AngularJS app imports-->
    <script src="/djangular/app.js"></script>  <!-- The djangular app. -->
    {% for dependency in app_dependencies %}
        {% compressed_js dependency %}
    {% endfor %}
    {% compressed_js app_name %}

</head>
<body ng-app="{{app_name}}">
    <div class="app" ng-view>
    </div>
</body>
</html>

djangular's People

Contributors

brian-montgomery avatar dzen avatar huuuze avatar nicholasserra avatar stephane avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

djangular's Issues

Question: is djangular going to survive the Angular2 transition?

This is a question about the future of Djangular, not an issue with the current Djangular for Angular 1.x
I just wanted to ask if you have time or plans to work djangular around the new Angular2 framework.
I'm in the process of learning Angular2 so I can't off the top of my head figure out the implications of all the changes to Angular to what you're doing with Djangular, but I guess the project layout based on Angular Seed will be outdated. I can imagine this awesome project could evolve with the Angular2 transition, but I'm trying to plan a little into the future and wanted to see if you've got any plans to do that, and if so approximately when that might happen, or if, like many things I've come to love in Angular 1.x, it is going to find a new home in the graveyard.
( I couldn't figure out how to label this as a question, perhaps only you can do that? )

stacktrace when using django test client to test views

With this unit test (simplified)

from django.test import TestCase, Client

class ViewTest(TestCase):
    def test_card_contents(self):
        c = Client()
        response = c.post('/card_contents', {'card_names': {}})

here's the trace:

Error
Traceback (most recent call last):
  File "/Users/rad3/development/cuesbey_repo/cuesbey_main/cube_diff/tests/test_views.py", line 10, in test_card_contents
    response = c.post('/card_contents', {'card_names': {}})
  File "/Users/rad3/development/cuesbey_repo/env/lib/python2.7/site-packages/django/test/client.py", line 449, in post
    response = super(Client, self).post(path, data=data, content_type=content_type, **extra)
  File "/Users/rad3/development/cuesbey_repo/env/lib/python2.7/site-packages/django/test/client.py", line 262, in post
    return self.request(**r)
  File "/Users/rad3/development/cuesbey_repo/env/lib/python2.7/site-packages/django/core/handlers/base.py", line 188, in get_response
    response = middleware_method(request, response)
  File "/Users/rad3/development/cuesbey_repo/cuesbey_main/djangular/middleware.py", line 14, in process_response
    if response['Content-Type'] in self.VALID_CONTENT_TYPES and response.status_code in self.VALID_STATUS_CODES:
TypeError: 'type' object is not subscriptable

I'm unsure if the middleware should just unloaded?

added some debug logging and found that this

TypeError: problem with <class 'django.http.Http404'> or ['application/json']

I guess a 404 is different somehow (my test is obviously at fault for causing a 404)

djangular's karma support should be updated, and can be enhanced

Djangular supports developers writing karma using these two management commands:

  • makeangularsite creates karma config file templates that handle the djangular app paths
  • testjs will shell out to karma and run the appropriate config file

the first is in need of an update:
as karma is on 0.12 and djangular writes out a file that's no longer compatible (I believe we're writing out a 0.8-style file, but there was backwards incompatible change in 0.9 or 0.10)

the second could use some enhancements:

  • the management command assumes that karma exists on the path (which isn't typical when not installing using npm -g)
  • there's no way to pass additional command line arguments to the karma invocation, which is useful for having jenkins run against PhantomJS and then letting developers override this at their desktops to run Firefox/Chrome
  • running testjs assume's that you have a very particular working directory so it can find an app's config files. It would be convenient let testjs work no matter your working directory.

django 1.4 stack traces on test manage.py commands

unsure how 1.5 v 1.4 things should be classified, could be a separate label

(env)jane:cuesbey_main rad3$ python manage.py testngunit -h
Traceback (most recent call last):
  File "manage.py", line 11, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/rad3/development/cuesbey_repo/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
    utility.execute()
  File "/Users/rad3/development/cuesbey_repo/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/rad3/development/cuesbey_repo/cuesbey_main/djangular/management/commands/__init__.py", line 34, in run_from_argv
    stdout = base.OutputWrapper(sys.stdout)
AttributeError: 'module' object has no attribute 'OutputWrapper'

OutputWrapper is in 1.5, but not in 1.4

Django 1.9: ImportError: cannot import name 'import_by_path'

traceback:

File "/opt/python-virtual-env/py35/lib/python3.5/site-packages/djangular/templatetags/djangular_tags.py", line 9, in
from djangular.core.urlresolvers import get_all_remote_methods, get_current_remote_methods, get_urls
File "/opt/python-virtual-env/py35/lib/python3.5/site-packages/djangular/core/urlresolvers.py", line 7, in
from django.utils.module_loading import import_by_path
ImportError: cannot import name 'import_by_path'

ImportError: cannot import name AppStaticStorage

python-3.3
django-1.7
called collectstatic

File "./manage.py", line 10, in
execute_from_command_line(sys.argv)
File "/home/qmax/Coding/djangularing/ENV/lib/python3.3/site-packages/django/core/management/init.py", line 385, in execute_from_command_line
utility.execute()
File "/home/qmax/Coding/djangularing/ENV/lib/python3.3/site-packages/django/core/management/init.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/qmax/Coding/djangularing/ENV/lib/python3.3/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(_args, *_options.dict)
File "/home/qmax/Coding/djangularing/ENV/lib/python3.3/site-packages/django/core/management/base.py", line 338, in execute
output = self.handle(_args, _options)
File "/home/qmax/Coding/djangularing/ENV/lib/python3.3/site-packages/django/core/management/base.py", line 533, in handle
return self.handle_noargs(
_options)
File "/home/qmax/Coding/djangularing/ENV/lib/python3.3/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 168, in handle_noargs
collected = self.collect()
File "/home/qmax/Coding/djangularing/ENV/lib/python3.3/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 97, in collect
for finder in get_finders():
File "/home/qmax/Coding/djangularing/ENV/lib/python3.3/site-packages/django/contrib/staticfiles/finders.py", line 263, in get_finders
yield get_finder(finder_path)
File "/home/qmax/Coding/djangularing/ENV/lib/python3.3/functools.py", line 251, in wrapper
result = user_function(_args, **kwds)
File "/home/qmax/Coding/djangularing/ENV/lib/python3.3/site-packages/django/contrib/staticfiles/finders.py", line 272, in get_finder
Finder = import_string(import_path)
File "/home/qmax/Coding/djangularing/ENV/lib/python3.3/site-packages/django/utils/module_loading.py", line 26, in import_string
module = import_module(module_path)
File "/home/qmax/Coding/djangularing/ENV/lib/python3.3/importlib/init.py", line 90, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1584, in _gcd_import
File "", line 1565, in _find_and_load
File "", line 1532, in _find_and_load_unlocked
File "", line 584, in _check_name_wrapper
File "", line 1022, in load_module
File "", line 1003, in load_module
File "", line 560, in module_for_loader_wrapper
File "", line 868, in _load_module
File "", line 313, in _call_with_frames_removed
File "/home/qmax/Coding/djangularing/ENV/lib/python3.3/site-packages/djangular/finders.py", line 1, in
from . import storage
File "/home/qmax/Coding/djangularing/ENV/lib/python3.3/site-packages/djangular/storage.py", line 3, in
from django.contrib.staticfiles.storage import AppStaticStorage
ImportError: cannot import name AppStaticStorage

re.sub 'bogus escape' error running under Windows

When running under windows the app path separators cause a 'bogus escape (end of line)' exception thrown by re.sub.

This is because the separator is two backslashes instead of a forward slash in windows. The two backslashes seriously confuse re.sub. The solution is to pass a raw string to sub.

In djangular/storage.py line 23 adding the correct string encoding fixes the problem:

name = sub('^' + self.prefix + os.sep.encode('string-escape'), '', name)

Thanks

Fragile way to get the angular site name

I don't understand why the makeangularsite try to extract the angular site name from the settings file. Is this an explicit (and required) argument would be better?

python3 support

Please, make a py3 version.
It seems like I've succeded to make it with 2to3.
But I don't know how to tests if it's completely fine.

django-1.7 startangularapp fails

django.core.exceptions.ImproperlyConfigured: Command Command defines both "requires_model_validation" and "requires_system_checks", which is illegal. Use only "requires_system_checks".

pip freeze:

Django==1.7
-e [email protected]:appliedsec/djangular.git@9a128aec030ae27ea01a2fa0673839ce5ad1fa6a#egg=djangular-origin_django_17_compatibility

v 0.2.5 and support for Angular 1.2.3

Today I installed djangular via pip ( pip shows djangular (0.2.5)) and I ended up with version 1.0.7 set by default.

I am using following code to include angular sources in templates:

        <script src="{{ STATIC_URL }}lib/angular/angular.js"></script>
        <script src="{{ STATIC_URL }}lib/angular/angular-cookies.js"></script>
        <script src="/djangular/app.js"></script>

I got it installed into site-packages ( using virtualenv ) and there are two directories: "djangular", which contains files for version 1.0.7 and "angular12", which containes files for version 1.2.3.

Command "makeangularapp" generates file structure for version 1.0.7 ( ngRoutes isn't included in app's dependencies and I know that module was pulled out of angular.js file in later version ).

I don't know how to use it properly to support angular 1.2.3 and I followed the instructions in readme. However as I browsed the content of this repo on github it shows sources for 1.2.3. I am quite confused, could you tell me how to set up this for 1.2.3?

Project no longer maintained?

@EliAndrewC hello, wondering if this project is no longer maintained? I'd like to use this for a Django 1.9 project. Do you need assistance in keeping it up to date? Let me know. I'd be interested in becoming a maintainer, or taking control of the project. Thanks!

Merging projects?

I started with a similar project. Its aim is to ease the integration of Angular with Django. Currently I added 3 independent features: validate froms managed by ng-controller; dispatch post requests to a handler; extract urls by namespace.

It could make sense, if we merge these projects, rather than having separate utilities.

Just have a look: https://github.com/jrief/django-angular

Docs currently are part of the code, I will add them soon to the project.

Support for Angular 1.2.0 version

I would like to use djangular with Angular version 1.2.0.

Is there any chance you could add support for version 1.2.0 ? ( it would be best if there was choice which version to use )

python manage.py startangularapp djangularTest does not work

hello
I want to use djangular in my django project but I have a problem. the problem is that when i want to create djangularapp in django project with this commant:
####### python manage.py startangularapp djangularTest #######
it shows me the below error:


C:\Users\Mohammad\Desktop\andjango>python manage.py startangularapp djangularTes t Traceback (most recent call last): File "manage.py", line 10, in
execute_from_command_line(sys.argv) File "C:\Python34\lib\site-packages\django\core\management__init__.py", line 338, in execute_from_command_line
utility.execute() File "C:\Python34\lib\site-packages\django\core\management__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv) File "C:\Python34\lib\site-packages\django\core\management\base.py", line 390, in run_from_argv
self.execute(_args, *_cmd_options) File "C:\Python34\lib\site-packages\django\core\management\base.py", line 441, in execute
output = self.handle(_args, *_options) File "C:\Python34\lib\site-packages\djangular-0.3.0b1-py3.4.egg\djangular\mana gement\commands\startangularapp.py", line 20, in handle
mgmt.call_command('startapp', app_name, target, **options)

TypeError: call_command() got multiple values for argument 'name'

i've tried to use multiple values but it does not work?
can anyone help me?
regards.

Adding extra directives to form elements?

Hey there,

Firstly, many thanks for creating this project. It makes life just so much simpler, and is infinitely appreciated.

One thing I'd ideally like to be able to do is add directives (specifically ngShow) to (some or all of) my form elements.

Ignorance isn't charming, but I do realise I'm sufficiently new to this to have potentially overlooked or misunderstood something fundamental, and my sincere apologies if that's the case.

Thanks.

readme should cover manage.py commands

[djangular]
    runtestserver
    startangularapp
    testnge2e
    testngunit

as part of a "so, you're using djangulat=r for the first time huh?" type of introduction

Serving partials with django?

Hi all,

I'm starting with djangular. I am trying to serve the partial files through Django instead of as static.

This way, the HTML goes first through the Django engine and can be formated, translated, ... all the django goodness!

I can see it seems doable in django-angular
http://django-angular.readthedocs.org/en/latest/integration.html#partials

I got a weird error when I try to do it myself. The app.js seems not capable of loading the content... It looks like it is looping and and re-calls itself, thus resulting in a chrome crashing the page.

angular.module('sample', ['djangular','sample.filters', 'sample.services', 'sample.directives', 'sample.controllers','ngCookies']).
 config([
   '$routeProvider',
   'DjangoProperties',
   function($routeProvider, DjangoProperties) {
       $routeProvider.when('/view1', {templateUrl: '/sample/partials/subview/template', controller: 'MyCtrl1'});
       $routeProvider.when('/view2', {templateUrl: DjangoProperties.STATIC_URL + 'sample/partials/partial2.html', controller: 'MyCtrl2'});
       $routeProvider.otherwise({redirectTo: '/view1'});
 }]).
   run([
   '$http',
   '$cookies',
   function($http, $cookies) {
       $http.defaults.headers.post['X-CSRFToken'] = $cookies.csrftoken;
   }]);

view2 et working fine.
view1 does not load. Btw, I can load with no problem localhost:8000/sample/partials/subview/template

Any idea?
Thanks a lot!

Vincent

Angular JS 1.3

Hello,

Is it possible to integrate the new version of angular js, version 1.3.

Thanks by advance.

collectstatic does not collect djangular static files

./manage.py collectstatic results in no djangular files being copied over - I had to copy them manually. This is under django 1.8 (and TBH it might be an issue with django).

django.contrib.staticfiles.finders.AppDirectoriesFinder is in the relevant place in settings.

Timeline for adding JS testing support

As this support was only recently dropped, with the comment "Removed JS Testing while it's being rewritten.", I wonder what your approximate timeline for this looks like.

The question is, should I go and implement this myself now or is it worth waiting a few weeks? I really liked the approach that was taken before, so I would probably end up doing it in a similar way anyway.

Thanks!

Getting ImportError: cannot import name DjangularModuleTemplateView

Hey I've been getting an Import error in the urls.py of my djangular installation. I've checked that the DjangularModuleTemplateView exists in views.py and tried even changing the import statement but nothing seems to work. Any ideas on what might be happening (Google/SO isn't helping)?

Here's my traceback:

[05/Mar/2015 11:04:24] ERROR [django.request:231] Internal Server Error: /favicon.ico
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/django/core/handlers/base.py", line 87, in get_response
response = middleware_method(request)
File "/Library/Python/2.7/site-packages/django/middleware/common.py", line 72, in process_request
if (not urlresolvers.is_valid_path(request.path_info, urlconf) and
File "/Library/Python/2.7/site-packages/django/core/urlresolvers.py", line 619, in is_valid_path
resolve(path, urlconf)
File "/Library/Python/2.7/site-packages/django/core/urlresolvers.py", line 494, in resolve
return get_resolver(urlconf).resolve(path)
File "/Library/Python/2.7/site-packages/django/core/urlresolvers.py", line 343, in resolve
for pattern in self.url_patterns:
File "/Library/Python/2.7/site-packages/django/core/urlresolvers.py", line 372, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/Library/Python/2.7/site-packages/django/core/urlresolvers.py", line 366, in urlconf_module
self._urlconf_module = import_module(self.urlconf_name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/init.py", line 37, in import_module
import(name)
File "/Users/user1/molescope-dev/molescope/urls.py", line 26, in
url(r'^djangular/', include('djangular.urls')),
File "/Library/Python/2.7/site-packages/django/conf/urls/init.py", line 28, in include
urlconf_module = import_module(urlconf_module)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/init.py", line 37, in import_module
import(name)
File "/Library/Python/2.7/site-packages/djangular/urls.py", line 2, in
from .views import DjangularModuleTemplateView
ImportError: cannot import name DjangularModuleTemplateView

Cannot import name 'AppStaticStorage'

I have an djangular app called characters and I'm trying to understand how to do url routing in django/angular works.

I've added the finders:

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    'djangular.finders.NamespacedAngularAppDirectoriesFinder'
)

But I'm getting A server error occurred. Please contact the administrator. when I try to access http://localhost:8000/static/characters/index.html/ and then the traceback below

[18/Feb/2015 16:19:21] "GET /static/characters/index.html/ HTTP/1.1" 500 59
Traceback (most recent call last):
  File "C:\Python34\lib\wsgiref\handlers.py", line 137, in run
    self.result = application(self.environ, self.start_response)
  File "C:\Python34\lib\site-packages\django\contrib\staticfiles\handlers.py", line 65, in __call__
    return super(StaticFilesHandler, self).__call__(environ, start_response)
  File "C:\Python34\lib\site-packages\django\core\handlers\wsgi.py", line 187, in __call__
    response = self.get_response(request)
  File "C:\Python34\lib\site-packages\django\contrib\staticfiles\handlers.py", line 55, in get_response
    return self.serve(request)
  File "C:\Python34\lib\site-packages\django\contrib\staticfiles\handlers.py", line 48, in serve
    return serve(request, self.file_path(request.path), insecure=True)
  File "C:\Python34\lib\site-packages\django\contrib\staticfiles\views.py", line 33, in serve
    absolute_path = finders.find(normalized_path)
  File "C:\Python34\lib\site-packages\django\contrib\staticfiles\finders.py", line 248, in find
    for finder in get_finders():
  File "C:\Python34\lib\site-packages\django\contrib\staticfiles\finders.py", line 263, in get_finders
    yield get_finder(finder_path)
  File "C:\Python34\lib\functools.py", line 434, in wrapper
    result = user_function(*args, **kwds)
  File "C:\Python34\lib\site-packages\django\contrib\staticfiles\finders.py", line 272, in get_finder
    Finder = import_string(import_path)
  File "C:\Python34\lib\site-packages\django\utils\module_loading.py", line 26, in import_string
    module = import_module(module_path)
  File "C:\Python34\lib\importlib\__init__.py", line 109, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1129, in _exec
  File "<frozen importlib._bootstrap>", line 1471, in exec_module
  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
  File "C:\Python34\lib\site-packages\djangular\finders.py", line 1, in <module>
    from . import storage
  File "C:\Python34\lib\site-packages\djangular\storage.py", line 3, in <module>
    from django.contrib.staticfiles.storage import AppStaticStorage
ImportError: cannot import name 'AppStaticStorage'

Any idea what I've done wrong?

In fact even running .\manage.py findstatic causes the same traceback!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.